{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "e9cff123",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "   <div id=\"bqD0Fs\"></div>\n",
       "   <script type=\"text/javascript\" data-lets-plot-script=\"library\">\n",
       "       if(!window.letsPlotCallQueue) {\n",
       "           window.letsPlotCallQueue = [];\n",
       "       }; \n",
       "       window.letsPlotCall = function(f) {\n",
       "           window.letsPlotCallQueue.push(f);\n",
       "       };\n",
       "       (function() {\n",
       "           var script = document.createElement(\"script\");\n",
       "           script.type = \"text/javascript\";\n",
       "           script.src = \"https://cdn.jsdelivr.net/gh/JetBrains/lets-plot@v4.3.0/js-package/distr/lets-plot.min.js\";\n",
       "           script.onload = function() {\n",
       "               window.letsPlotCall = function(f) {f();};\n",
       "               window.letsPlotCallQueue.forEach(function(f) {f();});\n",
       "               window.letsPlotCallQueue = [];\n",
       "               \n",
       "               \n",
       "           };\n",
       "           script.onerror = function(event) {\n",
       "               window.letsPlotCall = function(f) {};\n",
       "               window.letsPlotCallQueue = [];\n",
       "               var div = document.createElement(\"div\");\n",
       "               div.style.color = 'darkred';\n",
       "               div.textContent = 'Error loading Lets-Plot JS';\n",
       "               document.getElementById(\"bqD0Fs\").appendChild(div);\n",
       "           };\n",
       "           var e = document.getElementById(\"bqD0Fs\");\n",
       "           e.appendChild(script);\n",
       "       })();\n",
       "   </script>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "%useLatestDescriptors\n",
    "%use lets-plot"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "f27ed1dd",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Lets-Plot Kotlin API v.0.0.0-SNAPSHOT. Frontend: Notebook with dynamically loaded JS. Lets-Plot JS v.4.3.0."
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "LetsPlot.getInfo()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "22bed5b6",
   "metadata": {},
   "source": [
    "#### Set `themeGrey()` as default theme. It improves plots readability."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "19e17aad",
   "metadata": {},
   "outputs": [],
   "source": [
    "LetsPlot.theme = themeGrey()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8493d965",
   "metadata": {},
   "source": [
    "#### Data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "58d3ca1e",
   "metadata": {},
   "outputs": [],
   "source": [
    "val labelsData = mapOf(\n",
    "    \"x\" to listOf(0, 1, 2, 3, 4, 5, 6, 7, 8),\n",
    "    \"y\" to listOf(0, 45, 90, 135, 180, 225, 270, 315, 360),\n",
    "    \"r_y\" to listOf(360, 315, 270, 225, 180, 135, 90, 45, 0),\n",
    "    \"l\" to listOf(\"l0\", \"l45\", \"l90\", \"l135\", \"l180\", \"l225\", \"l270\", \"l315\", \"l360\"),\n",
    "    \"g\"  to listOf(\"g1\", \"g1\", \"g1\", \"g2\", \"g2\", \"g2\", \"g3\", \"g3\", \"g3\")\n",
    ")\n",
    "\n",
    "val lollipopData = mapOf(\n",
    "    \"c\" to listOf(\"a\", \"b\", \"c\", \"d\", \"e\", \"f\"),\n",
    "    \"x\" to listOf(1, 2, 3, 4, 5, 6),\n",
    "    \"y\" to listOf(1, 2, 3, 4, 5, 6)\n",
    ")\n",
    "\n",
    "val studentData = mapOf(\n",
    "    \"subj\" to listOf(\"progr\", \"math\", \"physic\", \"chemistry\", \"biology\"),\n",
    "    \"subjId\" to listOf(1, 2, 3, 4, 5),\n",
    "    \"student\" to List(5) { \"John\" },\n",
    "    \"score\" to listOf(19, 15, 18, 12, 9)\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d66230d8",
   "metadata": {},
   "source": [
    "# Geoms"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1701efea",
   "metadata": {},
   "source": [
    "## `geomArea()`\n",
    "Line get transformed into a circle:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "0e96441f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "   <div id=\"Hi69mQ\"></div>\n",
       "   <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n",
       "       (function() {\n",
       "           var plotSpec={\n",
       "\"layout\":{\n",
       "\"name\":\"grid\",\n",
       "\"ncol\":2,\n",
       "\"nrow\":1,\n",
       "\"fit\":true,\n",
       "\"align\":false\n",
       "},\n",
       "\"theme\":{\n",
       "\"name\":\"grey\"\n",
       "},\n",
       "\"figures\":[{\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "\"x\":\"x\",\n",
       "\"y\":\"y\"\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"position\":\"stack\",\n",
       "\"geom\":\"area\",\n",
       "\"data\":{\n",
       "\"x\":[0.0,1.0],\n",
       "\"y\":[1.0,1.0]\n",
       "}\n",
       "}],\n",
       "\"mapping\":{\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[]\n",
       "},{\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "\"x\":\"x\",\n",
       "\"y\":\"y\"\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"position\":\"stack\",\n",
       "\"geom\":\"area\",\n",
       "\"data\":{\n",
       "\"x\":[0.0,1.0],\n",
       "\"y\":[1.0,1.0]\n",
       "}\n",
       "}],\n",
       "\"mapping\":{\n",
       "},\n",
       "\"coord\":{\n",
       "\"name\":\"polar\"\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[]\n",
       "}],\n",
       "\"kind\":\"subplots\"\n",
       "};\n",
       "           var plotContainer = document.getElementById(\"Hi69mQ\");\n",
       "           window.letsPlotCall(function() {{\n",
       "               LetsPlot.buildPlotFromProcessedSpecs(plotSpec, -1, -1, plotContainer);\n",
       "           }});\n",
       "       })();\n",
       "   </script>"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "val p = letsPlot() + geomArea() { x = listOf(0, 1); y = listOf(1, 1) }\n",
    "\n",
    "gggrid(listOf(\n",
    "    p,\n",
    "    p + coordPolar()\n",
    "))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e71e86c1",
   "metadata": {},
   "source": [
    "### `flat = true`\n",
    "The plot can be transformed into a radar plot by using `flat = true` and a discrete x-scale."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "310d15d7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "   <div id=\"vUMk3w\"></div>\n",
       "   <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n",
       "       (function() {\n",
       "           var plotSpec={\n",
       "\"layout\":{\n",
       "\"name\":\"grid\",\n",
       "\"ncol\":3,\n",
       "\"nrow\":1,\n",
       "\"fit\":true,\n",
       "\"align\":false\n",
       "},\n",
       "\"theme\":{\n",
       "\"name\":\"grey\"\n",
       "},\n",
       "\"figures\":[{\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "\"x\":\"subjId\",\n",
       "\"y\":\"score\"\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"flat\":true,\n",
       "\"position\":\"stack\",\n",
       "\"geom\":\"area\",\n",
       "\"data\":{\n",
       "}\n",
       "},{\n",
       "\"mapping\":{\n",
       "\"x\":\"subjId\",\n",
       "\"y\":\"score\"\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"point\",\n",
       "\"data\":{\n",
       "}\n",
       "}],\n",
       "\"mapping\":{\n",
       "},\n",
       "\"data\":{\n",
       "\"score\":[19.0,15.0,18.0,12.0,9.0],\n",
       "\"subjId\":[1.0,2.0,3.0,4.0,5.0]\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[{\n",
       "\"aesthetic\":\"x\",\n",
       "\"breaks\":[1.0,2.0,3.0,4.0,5.0],\n",
       "\"labels\":[\"progr\",\"math\",\"physic\",\"chemistry\",\"biology\"]\n",
       "}]\n",
       "},{\n",
       "\"ggtitle\":{\n",
       "\"text\":\"scaleXContinuous\"\n",
       "},\n",
       "\"mapping\":{\n",
       "},\n",
       "\"coord\":{\n",
       "\"name\":\"polar\"\n",
       "},\n",
       "\"data\":{\n",
       "\"score\":[19.0,15.0,18.0,12.0,9.0],\n",
       "\"subjId\":[1.0,2.0,3.0,4.0,5.0]\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[{\n",
       "\"aesthetic\":\"x\",\n",
       "\"breaks\":[1.0,2.0,3.0,4.0,5.0],\n",
       "\"labels\":[\"progr\",\"math\",\"physic\",\"chemistry\",\"biology\"]\n",
       "}],\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "\"x\":\"subjId\",\n",
       "\"y\":\"score\"\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"flat\":true,\n",
       "\"position\":\"stack\",\n",
       "\"geom\":\"area\",\n",
       "\"data\":{\n",
       "}\n",
       "},{\n",
       "\"mapping\":{\n",
       "\"x\":\"subjId\",\n",
       "\"y\":\"score\"\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"point\",\n",
       "\"data\":{\n",
       "}\n",
       "}]\n",
       "},{\n",
       "\"ggtitle\":{\n",
       "\"text\":\"scaleXDiscrete\"\n",
       "},\n",
       "\"mapping\":{\n",
       "},\n",
       "\"coord\":{\n",
       "\"name\":\"polar\"\n",
       "},\n",
       "\"data\":{\n",
       "\"score\":[19.0,15.0,18.0,12.0,9.0],\n",
       "\"subjId\":[1.0,2.0,3.0,4.0,5.0]\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[{\n",
       "\"aesthetic\":\"x\",\n",
       "\"discrete\":true,\n",
       "\"breaks\":[1.0,2.0,3.0,4.0,5.0],\n",
       "\"labels\":[\"progr\",\"math\",\"physic\",\"chemistry\",\"biology\"]\n",
       "}],\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "\"x\":\"subjId\",\n",
       "\"y\":\"score\"\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"flat\":true,\n",
       "\"position\":\"stack\",\n",
       "\"geom\":\"area\",\n",
       "\"data\":{\n",
       "}\n",
       "},{\n",
       "\"mapping\":{\n",
       "\"x\":\"subjId\",\n",
       "\"y\":\"score\"\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"point\",\n",
       "\"data\":{\n",
       "}\n",
       "}]\n",
       "}],\n",
       "\"kind\":\"subplots\"\n",
       "};\n",
       "           var plotContainer = document.getElementById(\"vUMk3w\");\n",
       "           window.letsPlotCall(function() {{\n",
       "               LetsPlot.buildPlotFromProcessedSpecs(plotSpec, -1, -1, plotContainer);\n",
       "           }});\n",
       "       })();\n",
       "   </script>"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "val p = letsPlot(studentData) +\n",
    "    geomArea(flat = true) { x = \"subjId\"; y = \"score\" } +\n",
    "    geomPoint() { x = \"subjId\"; y = \"score\" }\n",
    "\n",
    "val labels = mapOf(1 to \"progr\", 2 to \"math\", 3 to \"physic\", 4 to \"chemistry\", 5 to \"biology\")\n",
    "\n",
    "val continuous = scaleXContinuous(labels = labels)\n",
    "val discrete = scaleXDiscrete(labels = labels)\n",
    "\n",
    "gggrid(listOf(\n",
    "    p + continuous,\n",
    "    p + continuous + coordPolar() + ggtitle(\"scaleXContinuous\"),\n",
    "    p + discrete + coordPolar() + ggtitle(\"scaleXDiscrete\"),\n",
    "))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "302a6755",
   "metadata": {},
   "source": [
    "## `geomSegment()`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "2631a836",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "   <div id=\"lGqXV4\"></div>\n",
       "   <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n",
       "       (function() {\n",
       "           var plotSpec={\n",
       "\"layout\":{\n",
       "\"name\":\"grid\",\n",
       "\"ncol\":2,\n",
       "\"nrow\":1,\n",
       "\"fit\":true,\n",
       "\"align\":false\n",
       "},\n",
       "\"theme\":{\n",
       "\"name\":\"grey\"\n",
       "},\n",
       "\"figures\":[{\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"size\":1.0,\n",
       "\"arrow\":{\n",
       "\"name\":\"arrow\"\n",
       "},\n",
       "\"x\":0.0,\n",
       "\"y\":0.0,\n",
       "\"yend\":4.0,\n",
       "\"position\":\"identity\",\n",
       "\"xend\":4.0,\n",
       "\"geom\":\"segment\",\n",
       "\"data\":{\n",
       "}\n",
       "},{\n",
       "\"mapping\":{\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"size\":1.0,\n",
       "\"arrow\":{\n",
       "\"name\":\"arrow\"\n",
       "},\n",
       "\"x\":8.0,\n",
       "\"y\":0.0,\n",
       "\"yend\":4.0,\n",
       "\"position\":\"identity\",\n",
       "\"xend\":4.0,\n",
       "\"geom\":\"segment\",\n",
       "\"data\":{\n",
       "}\n",
       "}],\n",
       "\"mapping\":{\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[]\n",
       "},{\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"size\":1.0,\n",
       "\"arrow\":{\n",
       "\"name\":\"arrow\"\n",
       "},\n",
       "\"x\":0.0,\n",
       "\"y\":0.0,\n",
       "\"yend\":4.0,\n",
       "\"position\":\"identity\",\n",
       "\"xend\":4.0,\n",
       "\"geom\":\"segment\",\n",
       "\"data\":{\n",
       "}\n",
       "},{\n",
       "\"mapping\":{\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"size\":1.0,\n",
       "\"arrow\":{\n",
       "\"name\":\"arrow\"\n",
       "},\n",
       "\"x\":8.0,\n",
       "\"y\":0.0,\n",
       "\"yend\":4.0,\n",
       "\"position\":\"identity\",\n",
       "\"xend\":4.0,\n",
       "\"geom\":\"segment\",\n",
       "\"data\":{\n",
       "}\n",
       "}],\n",
       "\"mapping\":{\n",
       "},\n",
       "\"coord\":{\n",
       "\"name\":\"polar\"\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[]\n",
       "}],\n",
       "\"kind\":\"subplots\"\n",
       "};\n",
       "           var plotContainer = document.getElementById(\"lGqXV4\");\n",
       "           window.letsPlotCall(function() {{\n",
       "               LetsPlot.buildPlotFromProcessedSpecs(plotSpec, -1, -1, plotContainer);\n",
       "           }});\n",
       "       })();\n",
       "   </script>"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "val p = letsPlot() +\n",
    "    geomSegment(x = 0, y = 0, xend = 4, yend = 4, arrow = arrow(), size = 1) +\n",
    "    geomSegment(x = 8, y = 0, xend = 4, yend = 4, arrow = arrow(), size = 1)\n",
    "\n",
    "gggrid(listOf(\n",
    "    p,\n",
    "    p + coordPolar()\n",
    "))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "905a37de",
   "metadata": {},
   "source": [
    "`sizeEnd`/`strokeEnd` precision length adjustment parameters:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "adcba1b0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "   <div id=\"icL5wi\"></div>\n",
       "   <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n",
       "       (function() {\n",
       "           var plotSpec={\n",
       "\"layout\":{\n",
       "\"name\":\"grid\",\n",
       "\"ncol\":2,\n",
       "\"nrow\":1,\n",
       "\"fit\":true,\n",
       "\"align\":false\n",
       "},\n",
       "\"theme\":{\n",
       "\"name\":\"grey\"\n",
       "},\n",
       "\"figures\":[{\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "\"size\":\"size\",\n",
       "\"stroke\":\"stroke\"\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"color\":\"red\",\n",
       "\"shape\":21.0,\n",
       "\"alpha\":0.5,\n",
       "\"show_legend\":false,\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"point\",\n",
       "\"data\":{\n",
       "}\n",
       "},{\n",
       "\"mapping\":{\n",
       "\"size_start\":\"size\",\n",
       "\"size_end\":\"size_end\",\n",
       "\"stroke_start\":\"stroke\",\n",
       "\"stroke_end\":\"stroke_end\"\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"size\":2.0,\n",
       "\"arrow\":{\n",
       "\"name\":\"arrow\",\n",
       "\"angle\":30.0,\n",
       "\"length\":22.0,\n",
       "\"ends\":\"both\",\n",
       "\"type\":\"open\"\n",
       "},\n",
       "\"yend\":0.0,\n",
       "\"position\":\"identity\",\n",
       "\"xend\":1.0,\n",
       "\"geom\":\"segment\",\n",
       "\"data\":{\n",
       "}\n",
       "}],\n",
       "\"mapping\":{\n",
       "\"x\":\"x\",\n",
       "\"y\":\"y\"\n",
       "},\n",
       "\"data\":{\n",
       "\"size\":[8.0,10.0],\n",
       "\"x\":[0.0,1.0],\n",
       "\"stroke_end\":[2.0,0.0],\n",
       "\"y\":[0.0,0.0],\n",
       "\"stroke\":[1.0,2.0],\n",
       "\"size_end\":[10.0,0.0]\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[{\n",
       "\"aesthetic\":\"size\",\n",
       "\"scale_mapper_kind\":\"identity\",\n",
       "\"guide\":\"none\"\n",
       "}]\n",
       "},{\n",
       "\"mapping\":{\n",
       "\"x\":\"x\",\n",
       "\"y\":\"y\"\n",
       "},\n",
       "\"coord\":{\n",
       "\"name\":\"polar\",\n",
       "\"xlim\":[-0.35,1.35],\n",
       "\"ylim\":[-2.0,2.0]\n",
       "},\n",
       "\"data\":{\n",
       "\"size\":[8.0,10.0],\n",
       "\"x\":[0.0,1.0],\n",
       "\"stroke_end\":[2.0,0.0],\n",
       "\"y\":[0.0,0.0],\n",
       "\"stroke\":[1.0,2.0],\n",
       "\"size_end\":[10.0,0.0]\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[{\n",
       "\"aesthetic\":\"size\",\n",
       "\"scale_mapper_kind\":\"identity\",\n",
       "\"guide\":\"none\"\n",
       "}],\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "\"size\":\"size\",\n",
       "\"stroke\":\"stroke\"\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"color\":\"red\",\n",
       "\"shape\":21.0,\n",
       "\"alpha\":0.5,\n",
       "\"show_legend\":false,\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"point\",\n",
       "\"data\":{\n",
       "}\n",
       "},{\n",
       "\"mapping\":{\n",
       "\"size_start\":\"size\",\n",
       "\"size_end\":\"size_end\",\n",
       "\"stroke_start\":\"stroke\",\n",
       "\"stroke_end\":\"stroke_end\"\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"size\":2.0,\n",
       "\"arrow\":{\n",
       "\"name\":\"arrow\",\n",
       "\"angle\":30.0,\n",
       "\"length\":22.0,\n",
       "\"ends\":\"both\",\n",
       "\"type\":\"open\"\n",
       "},\n",
       "\"yend\":0.0,\n",
       "\"position\":\"identity\",\n",
       "\"xend\":1.0,\n",
       "\"geom\":\"segment\",\n",
       "\"data\":{\n",
       "}\n",
       "}]\n",
       "}],\n",
       "\"kind\":\"subplots\"\n",
       "};\n",
       "           var plotContainer = document.getElementById(\"icL5wi\");\n",
       "           window.letsPlotCall(function() {{\n",
       "               LetsPlot.buildPlotFromProcessedSpecs(plotSpec, -1, -1, plotContainer);\n",
       "           }});\n",
       "       })();\n",
       "   </script>"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "// known problem - zero-length segment because of second datapoint.\n",
    "// this is a temp workaround to sync stroke/stroke_end and size/size_ens domains\n",
    "val d = mapOf( \n",
    "    \"x\" to listOf(0, 1),\n",
    "    \"y\" to listOf(0, 0),\n",
    "    \"size\" to listOf(8, 10), \n",
    "    \"stroke\" to listOf(1, 2),\n",
    "    \"size_end\" to listOf(10, 0), \n",
    "    \"stroke_end\" to listOf(2, 0)\n",
    ")\n",
    "\n",
    "val p = letsPlot(d) { x = \"x\"; y = \"y\" } +\n",
    "    geomPoint(shape = 21, alpha = 0.5, color = \"red\", showLegend = false) { size = \"size\"; stroke = \"stroke\" } +\n",
    "    geomSegment(xend = 1, yend = 0, size = 2,\n",
    "                arrow = arrow(ends = \"both\", type = \"open\", length = 22, angle = 30)) {\n",
    "        sizeStart = \"size\" \n",
    "        strokeStart = \"stroke\";\n",
    "        sizeEnd = \"size_end\"\n",
    "        strokeEnd = \"stroke_end\"\n",
    "    } +\n",
    "    scaleSizeIdentity()\n",
    "\n",
    "gggrid(listOf(\n",
    "    p,\n",
    "    p + coordPolar(xlim = -0.35 to 1.35, ylim = -2 to 2) // lims are only to make the figure smiling\n",
    "))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b6cdd2cb",
   "metadata": {},
   "source": [
    "## `geomLabel()`\n",
    "Regular scatter plot."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "3a5077c9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "   <div id=\"FxWYsw\"></div>\n",
       "   <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n",
       "       (function() {\n",
       "           var plotSpec={\n",
       "\"layout\":{\n",
       "\"name\":\"grid\",\n",
       "\"ncol\":3,\n",
       "\"nrow\":1,\n",
       "\"fit\":true,\n",
       "\"align\":false\n",
       "},\n",
       "\"theme\":{\n",
       "\"name\":\"grey\"\n",
       "},\n",
       "\"figures\":[{\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"label\",\n",
       "\"data\":{\n",
       "}\n",
       "}],\n",
       "\"mapping\":{\n",
       "\"x\":\"x\",\n",
       "\"y\":\"y\",\n",
       "\"label\":\"l\"\n",
       "},\n",
       "\"data\":{\n",
       "\"x\":[0.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0],\n",
       "\"y\":[0.0,45.0,90.0,135.0,180.0,225.0,270.0,315.0,360.0],\n",
       "\"l\":[\"l0\",\"l45\",\"l90\",\"l135\",\"l180\",\"l225\",\"l270\",\"l315\",\"l360\"]\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[]\n",
       "},{\n",
       "\"ggtitle\":{\n",
       "\"text\":\"coordPolar()\"\n",
       "},\n",
       "\"mapping\":{\n",
       "\"x\":\"x\",\n",
       "\"y\":\"y\",\n",
       "\"label\":\"l\"\n",
       "},\n",
       "\"coord\":{\n",
       "\"name\":\"polar\"\n",
       "},\n",
       "\"data\":{\n",
       "\"x\":[0.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0],\n",
       "\"y\":[0.0,45.0,90.0,135.0,180.0,225.0,270.0,315.0,360.0],\n",
       "\"l\":[\"l0\",\"l45\",\"l90\",\"l135\",\"l180\",\"l225\",\"l270\",\"l315\",\"l360\"]\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[],\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"label\",\n",
       "\"data\":{\n",
       "}\n",
       "}]\n",
       "},{\n",
       "\"ggtitle\":{\n",
       "\"text\":\"theta=y\"\n",
       "},\n",
       "\"mapping\":{\n",
       "\"x\":\"x\",\n",
       "\"y\":\"y\",\n",
       "\"label\":\"l\"\n",
       "},\n",
       "\"coord\":{\n",
       "\"name\":\"polar\",\n",
       "\"theta\":\"y\"\n",
       "},\n",
       "\"data\":{\n",
       "\"x\":[0.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0],\n",
       "\"y\":[0.0,45.0,90.0,135.0,180.0,225.0,270.0,315.0,360.0],\n",
       "\"l\":[\"l0\",\"l45\",\"l90\",\"l135\",\"l180\",\"l225\",\"l270\",\"l315\",\"l360\"]\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[],\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"label\",\n",
       "\"data\":{\n",
       "}\n",
       "}]\n",
       "}],\n",
       "\"kind\":\"subplots\"\n",
       "};\n",
       "           var plotContainer = document.getElementById(\"FxWYsw\");\n",
       "           window.letsPlotCall(function() {{\n",
       "               LetsPlot.buildPlotFromProcessedSpecs(plotSpec, -1, -1, plotContainer);\n",
       "           }});\n",
       "       })();\n",
       "   </script>"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "val p = letsPlot(labelsData) { x = \"x\"; y = \"y\"; label = \"l\" } + geomLabel()\n",
    "\n",
    "gggrid(listOf(\n",
    "    p, \n",
    "    p + coordPolar() + ggtitle(\"coordPolar()\"),\n",
    "    p + coordPolar(theta = \"y\") + ggtitle(\"theta=y\"),\n",
    "))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7bd3a25e",
   "metadata": {},
   "source": [
    "## `geomPath()`\n",
    "The transform resamples path data by converting straight segments into curves. The `flat` parameter controls this behaviour."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "7b3acdd4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "   <div id=\"PYZ1e9\"></div>\n",
       "   <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n",
       "       (function() {\n",
       "           var plotSpec={\n",
       "\"layout\":{\n",
       "\"name\":\"grid\",\n",
       "\"ncol\":2,\n",
       "\"nrow\":1,\n",
       "\"fit\":true,\n",
       "\"align\":false\n",
       "},\n",
       "\"theme\":{\n",
       "\"name\":\"grey\"\n",
       "},\n",
       "\"figures\":[{\n",
       "\"ggtitle\":{\n",
       "\"text\":\"coordPolar()\"\n",
       "},\n",
       "\"mapping\":{\n",
       "\"x\":\"x\",\n",
       "\"y\":\"y\",\n",
       "\"color\":\"y\"\n",
       "},\n",
       "\"coord\":{\n",
       "\"name\":\"polar\"\n",
       "},\n",
       "\"data\":{\n",
       "\"x\":[0.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0],\n",
       "\"y\":[0.0,45.0,90.0,135.0,180.0,225.0,270.0,315.0,360.0]\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[{\n",
       "\"aesthetic\":\"color\",\n",
       "\"scale_mapper_kind\":\"color_brewer\",\n",
       "\"palette\":\"GnBu\"\n",
       "}],\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"size\":3.0,\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"path\",\n",
       "\"data\":{\n",
       "}\n",
       "}]\n",
       "},{\n",
       "\"ggtitle\":{\n",
       "\"text\":\"coordPolar(), flat=true\"\n",
       "},\n",
       "\"mapping\":{\n",
       "\"x\":\"x\",\n",
       "\"y\":\"y\",\n",
       "\"color\":\"y\"\n",
       "},\n",
       "\"coord\":{\n",
       "\"name\":\"polar\",\n",
       "\"theta\":\"x\"\n",
       "},\n",
       "\"data\":{\n",
       "\"x\":[0.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0],\n",
       "\"y\":[0.0,45.0,90.0,135.0,180.0,225.0,270.0,315.0,360.0]\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[{\n",
       "\"aesthetic\":\"color\",\n",
       "\"scale_mapper_kind\":\"color_brewer\",\n",
       "\"palette\":\"GnBu\"\n",
       "}],\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"size\":3.0,\n",
       "\"flat\":true,\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"path\",\n",
       "\"data\":{\n",
       "}\n",
       "}]\n",
       "}],\n",
       "\"kind\":\"subplots\"\n",
       "};\n",
       "           var plotContainer = document.getElementById(\"PYZ1e9\");\n",
       "           window.letsPlotCall(function() {{\n",
       "               LetsPlot.buildPlotFromProcessedSpecs(plotSpec, -1, -1, plotContainer);\n",
       "           }});\n",
       "       })();\n",
       "   </script>"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "val p = letsPlot(labelsData) { x = \"x\"; y = \"y\"; color = \"y\" } + scaleColorBrewer(palette = \"GnBu\")\n",
    "\n",
    "gggrid(listOf(\n",
    "    p + geomPath(size = 3) + coordPolar() + ggtitle(\"coordPolar()\"),\n",
    "    p + geomPath(size = 3, flat = true) + coordPolar(theta = \"x\") + ggtitle(\"coordPolar(), flat=true\")\n",
    "), ncol=2)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b92bad8b",
   "metadata": {},
   "source": [
    "### Autoclose on a discrete x-scale"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "82e42a31",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "   <div id=\"ANXA8v\"></div>\n",
       "   <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n",
       "       (function() {\n",
       "           var plotSpec={\n",
       "\"mapping\":{\n",
       "},\n",
       "\"coord\":{\n",
       "\"name\":\"polar\",\n",
       "\"ylim\":[0.0,20.0]\n",
       "},\n",
       "\"data\":{\n",
       "\"score\":[19.0,15.0,18.0,12.0,9.0],\n",
       "\"subj\":[\"progr\",\"math\",\"physic\",\"chemistry\",\"biology\"]\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[],\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "\"x\":\"subj\",\n",
       "\"y\":\"score\"\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"flat\":true,\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"path\",\n",
       "\"data\":{\n",
       "}\n",
       "}],\n",
       "\"theme\":{\n",
       "\"name\":\"grey\"\n",
       "}\n",
       "};\n",
       "           var plotContainer = document.getElementById(\"ANXA8v\");\n",
       "           window.letsPlotCall(function() {{\n",
       "               LetsPlot.buildPlotFromProcessedSpecs(plotSpec, -1, -1, plotContainer);\n",
       "           }});\n",
       "       })();\n",
       "   </script>"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ggplot(studentData) + geomPath(flat = true) { x = \"subj\"; y = \"score\" } + coordPolar(ylim = 0 to 20)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a5a9f07e",
   "metadata": {},
   "source": [
    "## `geomLollipop()`\n",
    "See the `Params` section for details on using the `ylim` parameters."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "97bbaa08",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "   <div id=\"KsT9v8\"></div>\n",
       "   <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n",
       "       (function() {\n",
       "           var plotSpec={\n",
       "\"layout\":{\n",
       "\"name\":\"grid\",\n",
       "\"ncol\":2,\n",
       "\"nrow\":1,\n",
       "\"fit\":true,\n",
       "\"align\":false\n",
       "},\n",
       "\"theme\":{\n",
       "\"name\":\"grey\"\n",
       "},\n",
       "\"figures\":[{\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"lollipop\",\n",
       "\"data\":{\n",
       "}\n",
       "}],\n",
       "\"mapping\":{\n",
       "\"x\":\"c\",\n",
       "\"y\":\"y\"\n",
       "},\n",
       "\"data\":{\n",
       "\"c\":[\"a\",\"b\",\"c\",\"d\",\"e\",\"f\"],\n",
       "\"y\":[1.0,2.0,3.0,4.0,5.0,6.0]\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[]\n",
       "},{\n",
       "\"mapping\":{\n",
       "\"x\":\"c\",\n",
       "\"y\":\"y\"\n",
       "},\n",
       "\"coord\":{\n",
       "\"name\":\"polar\"\n",
       "},\n",
       "\"data\":{\n",
       "\"c\":[\"a\",\"b\",\"c\",\"d\",\"e\",\"f\"],\n",
       "\"y\":[1.0,2.0,3.0,4.0,5.0,6.0]\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[],\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"lollipop\",\n",
       "\"data\":{\n",
       "}\n",
       "}]\n",
       "}],\n",
       "\"kind\":\"subplots\"\n",
       "};\n",
       "           var plotContainer = document.getElementById(\"KsT9v8\");\n",
       "           window.letsPlotCall(function() {{\n",
       "               LetsPlot.buildPlotFromProcessedSpecs(plotSpec, -1, -1, plotContainer);\n",
       "           }});\n",
       "       })();\n",
       "   </script>"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "val p = letsPlot(lollipopData) { x = \"c\"; y = \"y\" } + geomLollipop()\n",
    "\n",
    "gggrid(listOf(\n",
    "    p, \n",
    "    p + coordPolar()\n",
    "))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "151574dc",
   "metadata": {},
   "source": [
    "## `geomBar()` \n",
    "This works similarly to rects, but with the addition of tooltips."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d7e89e70",
   "metadata": {},
   "source": [
    "### `position='stack'`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "37245cb7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "   <div id=\"dLdxKl\"></div>\n",
       "   <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n",
       "       (function() {\n",
       "           var plotSpec={\n",
       "\"layout\":{\n",
       "\"name\":\"grid\",\n",
       "\"ncol\":3,\n",
       "\"nrow\":1,\n",
       "\"fit\":true,\n",
       "\"align\":false\n",
       "},\n",
       "\"theme\":{\n",
       "\"name\":\"grey\"\n",
       "},\n",
       "\"figures\":[{\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "\"fill\":\"foo\"\n",
       "},\n",
       "\"stat\":\"count\",\n",
       "\"size\":0.0,\n",
       "\"position\":\"stack\",\n",
       "\"geom\":\"bar\",\n",
       "\"data_meta\":{\n",
       "\"mapping_annotations\":[{\n",
       "\"aes\":\"fill\",\n",
       "\"annotation\":\"as_discrete\",\n",
       "\"parameters\":{\n",
       "\"label\":\"foo\",\n",
       "\"order\":1\n",
       "}\n",
       "}]\n",
       "},\n",
       "\"data\":{\n",
       "\"..x..\":[0.0,0.0,0.0],\n",
       "\"..count..\":[7.0,4.0,3.0],\n",
       "\"foo\":[1.0,2.0,3.0]\n",
       "}\n",
       "}],\n",
       "\"mapping\":{\n",
       "},\n",
       "\"data\":{\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[]\n",
       "},{\n",
       "\"ggtitle\":{\n",
       "\"text\":\"position=stack, coord_polar(theta=y)\"\n",
       "},\n",
       "\"mapping\":{\n",
       "},\n",
       "\"coord\":{\n",
       "\"name\":\"polar\",\n",
       "\"theta\":\"y\"\n",
       "},\n",
       "\"data\":{\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[],\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "\"fill\":\"foo\"\n",
       "},\n",
       "\"stat\":\"count\",\n",
       "\"size\":0.0,\n",
       "\"position\":\"stack\",\n",
       "\"geom\":\"bar\",\n",
       "\"data_meta\":{\n",
       "\"mapping_annotations\":[{\n",
       "\"aes\":\"fill\",\n",
       "\"annotation\":\"as_discrete\",\n",
       "\"parameters\":{\n",
       "\"label\":\"foo\",\n",
       "\"order\":1\n",
       "}\n",
       "}]\n",
       "},\n",
       "\"data\":{\n",
       "\"..x..\":[0.0,0.0,0.0],\n",
       "\"..count..\":[7.0,4.0,3.0],\n",
       "\"foo\":[1.0,2.0,3.0]\n",
       "}\n",
       "}]\n",
       "},{\n",
       "\"ggtitle\":{\n",
       "\"text\":\"position=stack, coord_polar(theta=x)\"\n",
       "},\n",
       "\"mapping\":{\n",
       "},\n",
       "\"coord\":{\n",
       "\"name\":\"polar\",\n",
       "\"theta\":\"x\"\n",
       "},\n",
       "\"data\":{\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[],\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "\"fill\":\"foo\"\n",
       "},\n",
       "\"stat\":\"count\",\n",
       "\"size\":0.0,\n",
       "\"position\":\"stack\",\n",
       "\"geom\":\"bar\",\n",
       "\"data_meta\":{\n",
       "\"mapping_annotations\":[{\n",
       "\"aes\":\"fill\",\n",
       "\"annotation\":\"as_discrete\",\n",
       "\"parameters\":{\n",
       "\"label\":\"foo\",\n",
       "\"order\":1\n",
       "}\n",
       "}]\n",
       "},\n",
       "\"data\":{\n",
       "\"..x..\":[0.0,0.0,0.0],\n",
       "\"..count..\":[7.0,4.0,3.0],\n",
       "\"foo\":[1.0,2.0,3.0]\n",
       "}\n",
       "}]\n",
       "}],\n",
       "\"kind\":\"subplots\"\n",
       "};\n",
       "           var plotContainer = document.getElementById(\"dLdxKl\");\n",
       "           window.letsPlotCall(function() {{\n",
       "               LetsPlot.buildPlotFromProcessedSpecs(plotSpec, -1, -1, plotContainer);\n",
       "           }});\n",
       "       })();\n",
       "   </script>"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "val barData = mapOf(\"foo\" to listOf(1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3))\n",
    "val p = letsPlot(barData) + geomBar(size = 0) { fill = asDiscrete(\"foo\", order = 1) }\n",
    "\n",
    "gggrid(listOf(\n",
    "    p,\n",
    "    p + coordPolar(theta=\"y\") + ggtitle(\"position=stack, coord_polar(theta=y)\"),\n",
    "    p + coordPolar(theta=\"x\") + ggtitle(\"position=stack, coord_polar(theta=x)\"),\n",
    "))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "56d2d740",
   "metadata": {},
   "source": [
    "### `position='dodge'`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "79aeaf6f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "   <div id=\"tBlUUj\"></div>\n",
       "   <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n",
       "       (function() {\n",
       "           var plotSpec={\n",
       "\"layout\":{\n",
       "\"name\":\"grid\",\n",
       "\"ncol\":3,\n",
       "\"nrow\":1,\n",
       "\"fit\":true,\n",
       "\"align\":false\n",
       "},\n",
       "\"theme\":{\n",
       "\"name\":\"grey\"\n",
       "},\n",
       "\"figures\":[{\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "\"fill\":\"foo\"\n",
       "},\n",
       "\"stat\":\"count\",\n",
       "\"size\":0.0,\n",
       "\"position\":\"dodge\",\n",
       "\"geom\":\"bar\",\n",
       "\"data_meta\":{\n",
       "\"mapping_annotations\":[{\n",
       "\"aes\":\"fill\",\n",
       "\"annotation\":\"as_discrete\",\n",
       "\"parameters\":{\n",
       "\"label\":\"foo\",\n",
       "\"order\":1\n",
       "}\n",
       "}]\n",
       "},\n",
       "\"data\":{\n",
       "\"..x..\":[0.0,0.0,0.0],\n",
       "\"..count..\":[7.0,4.0,3.0],\n",
       "\"foo\":[1.0,2.0,3.0]\n",
       "}\n",
       "}],\n",
       "\"mapping\":{\n",
       "},\n",
       "\"data\":{\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[]\n",
       "},{\n",
       "\"ggtitle\":{\n",
       "\"text\":\"position=dodge, coord_polar(theta=y)\"\n",
       "},\n",
       "\"mapping\":{\n",
       "},\n",
       "\"coord\":{\n",
       "\"name\":\"polar\",\n",
       "\"theta\":\"y\"\n",
       "},\n",
       "\"data\":{\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[],\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "\"fill\":\"foo\"\n",
       "},\n",
       "\"stat\":\"count\",\n",
       "\"size\":0.0,\n",
       "\"position\":\"dodge\",\n",
       "\"geom\":\"bar\",\n",
       "\"data_meta\":{\n",
       "\"mapping_annotations\":[{\n",
       "\"aes\":\"fill\",\n",
       "\"annotation\":\"as_discrete\",\n",
       "\"parameters\":{\n",
       "\"label\":\"foo\",\n",
       "\"order\":1\n",
       "}\n",
       "}]\n",
       "},\n",
       "\"data\":{\n",
       "\"..x..\":[0.0,0.0,0.0],\n",
       "\"..count..\":[7.0,4.0,3.0],\n",
       "\"foo\":[1.0,2.0,3.0]\n",
       "}\n",
       "}]\n",
       "},{\n",
       "\"ggtitle\":{\n",
       "\"text\":\"position=dodge, coord_polar(theta=x)\"\n",
       "},\n",
       "\"mapping\":{\n",
       "},\n",
       "\"coord\":{\n",
       "\"name\":\"polar\",\n",
       "\"theta\":\"x\"\n",
       "},\n",
       "\"data\":{\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[],\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "\"fill\":\"foo\"\n",
       "},\n",
       "\"stat\":\"count\",\n",
       "\"size\":0.0,\n",
       "\"position\":\"dodge\",\n",
       "\"geom\":\"bar\",\n",
       "\"data_meta\":{\n",
       "\"mapping_annotations\":[{\n",
       "\"aes\":\"fill\",\n",
       "\"annotation\":\"as_discrete\",\n",
       "\"parameters\":{\n",
       "\"label\":\"foo\",\n",
       "\"order\":1\n",
       "}\n",
       "}]\n",
       "},\n",
       "\"data\":{\n",
       "\"..x..\":[0.0,0.0,0.0],\n",
       "\"..count..\":[7.0,4.0,3.0],\n",
       "\"foo\":[1.0,2.0,3.0]\n",
       "}\n",
       "}]\n",
       "}],\n",
       "\"kind\":\"subplots\"\n",
       "};\n",
       "           var plotContainer = document.getElementById(\"tBlUUj\");\n",
       "           window.letsPlotCall(function() {{\n",
       "               LetsPlot.buildPlotFromProcessedSpecs(plotSpec, -1, -1, plotContainer);\n",
       "           }});\n",
       "       })();\n",
       "   </script>"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "val p = letsPlot(barData) + geomBar(size = 0, position = positionDodge()) { fill = asDiscrete(\"foo\", order = 1) }\n",
    "\n",
    "gggrid(listOf(\n",
    "    p,\n",
    "    p + coordPolar(theta=\"y\") + ggtitle(\"position=dodge, coord_polar(theta=y)\"),\n",
    "    p + coordPolar(theta=\"x\") + ggtitle(\"position=dodge, coord_polar(theta=x)\"),\n",
    "))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d076e78b",
   "metadata": {},
   "source": [
    "### `stat='identity'`\n",
    "On a continuous x-scale the first and last bars stuck. The `expand` parameter can be used to fix this."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "1fce12df",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "   <div id=\"KF0w35\"></div>\n",
       "   <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n",
       "       (function() {\n",
       "           var plotSpec={\n",
       "\"layout\":{\n",
       "\"name\":\"grid\",\n",
       "\"ncol\":2,\n",
       "\"nrow\":1,\n",
       "\"fit\":true,\n",
       "\"align\":false\n",
       "},\n",
       "\"theme\":{\n",
       "\"name\":\"grey\"\n",
       "},\n",
       "\"figures\":[{\n",
       "\"ggtitle\":{\n",
       "\"text\":\"Continuous x\"\n",
       "},\n",
       "\"mapping\":{\n",
       "},\n",
       "\"coord\":{\n",
       "\"name\":\"polar\"\n",
       "},\n",
       "\"data\":{\n",
       "\"x\":[1.0,2.0,3.0],\n",
       "\"y\":[5.0,3.0,4.0]\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[],\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "\"x\":\"x\",\n",
       "\"y\":\"y\"\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"width\":0.8,\n",
       "\"position\":\"stack\",\n",
       "\"geom\":\"bar\",\n",
       "\"data\":{\n",
       "}\n",
       "}]\n",
       "},{\n",
       "\"ggtitle\":{\n",
       "\"text\":\"scaleXContinuous(expand=[0, 0.1))\"\n",
       "},\n",
       "\"mapping\":{\n",
       "},\n",
       "\"coord\":{\n",
       "\"name\":\"polar\"\n",
       "},\n",
       "\"data\":{\n",
       "\"x\":[1.0,2.0,3.0],\n",
       "\"y\":[5.0,3.0,4.0]\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[{\n",
       "\"aesthetic\":\"x\",\n",
       "\"expand\":[0,0.1]\n",
       "}],\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "\"x\":\"x\",\n",
       "\"y\":\"y\"\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"width\":0.8,\n",
       "\"position\":\"stack\",\n",
       "\"geom\":\"bar\",\n",
       "\"data\":{\n",
       "}\n",
       "}]\n",
       "}],\n",
       "\"kind\":\"subplots\"\n",
       "};\n",
       "           var plotContainer = document.getElementById(\"KF0w35\");\n",
       "           window.letsPlotCall(function() {{\n",
       "               LetsPlot.buildPlotFromProcessedSpecs(plotSpec, -1, -1, plotContainer);\n",
       "           }});\n",
       "       })();\n",
       "   </script>"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "val data = mapOf(\n",
    "    \"x\" to listOf(1, 2, 3),\n",
    "    \"y\" to listOf(5, 3, 4)\n",
    ")\n",
    "\n",
    "val barId = letsPlot(data) + geomBar(stat = Stat.identity, width = 0.8) { x = \"x\"; y = \"y\" } + coordPolar()\n",
    "\n",
    "gggrid(listOf(\n",
    "    barId + ggtitle(\"Continuous x\"),\n",
    "    barId + scaleXContinuous(expand = listOf(0, 0.1)) + ggtitle(\"scaleXContinuous(expand=[0, 0.1))\")\n",
    "))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "1372b27c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "   <div id=\"MnFd3K\"></div>\n",
       "   <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n",
       "       (function() {\n",
       "           var plotSpec={\n",
       "\"ggtitle\":{\n",
       "\"text\":\"Discrete x\"\n",
       "},\n",
       "\"mapping\":{\n",
       "},\n",
       "\"coord\":{\n",
       "\"name\":\"polar\"\n",
       "},\n",
       "\"data\":{\n",
       "\"x\":[1.0,2.0,3.0],\n",
       "\"y\":[5.0,3.0,4.0]\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[{\n",
       "\"aesthetic\":\"x\",\n",
       "\"discrete\":true\n",
       "}],\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "\"x\":\"x\",\n",
       "\"y\":\"y\"\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"width\":0.8,\n",
       "\"position\":\"stack\",\n",
       "\"geom\":\"bar\",\n",
       "\"data\":{\n",
       "}\n",
       "}],\n",
       "\"theme\":{\n",
       "\"name\":\"grey\"\n",
       "}\n",
       "};\n",
       "           var plotContainer = document.getElementById(\"MnFd3K\");\n",
       "           window.letsPlotCall(function() {{\n",
       "               LetsPlot.buildPlotFromProcessedSpecs(plotSpec, -1, -1, plotContainer);\n",
       "           }});\n",
       "       })();\n",
       "   </script>"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "barId + scaleXDiscrete() + ggtitle(\"Discrete x\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a7084648",
   "metadata": {},
   "source": [
    "## `geomHLine()`/`geomVLine()`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "4506efab",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "   <div id=\"yDf20Q\"></div>\n",
       "   <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n",
       "       (function() {\n",
       "           var plotSpec={\n",
       "\"layout\":{\n",
       "\"name\":\"grid\",\n",
       "\"ncol\":2,\n",
       "\"nrow\":1,\n",
       "\"fit\":true,\n",
       "\"align\":false\n",
       "},\n",
       "\"theme\":{\n",
       "\"name\":\"grey\"\n",
       "},\n",
       "\"figures\":[{\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"yintercept\":5.0,\n",
       "\"color\":\"red\",\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"hline\",\n",
       "\"data\":{\n",
       "}\n",
       "},{\n",
       "\"mapping\":{\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"yintercept\":10.0,\n",
       "\"color\":\"green\",\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"hline\",\n",
       "\"data\":{\n",
       "}\n",
       "},{\n",
       "\"mapping\":{\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"yintercept\":15.0,\n",
       "\"color\":\"blue\",\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"hline\",\n",
       "\"data\":{\n",
       "}\n",
       "},{\n",
       "\"mapping\":{\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"yintercept\":20.0,\n",
       "\"color\":\"orange\",\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"hline\",\n",
       "\"data\":{\n",
       "}\n",
       "},{\n",
       "\"mapping\":{\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"color\":\"pink\",\n",
       "\"position\":\"identity\",\n",
       "\"xintercept\":10.0,\n",
       "\"geom\":\"vline\",\n",
       "\"data\":{\n",
       "}\n",
       "},{\n",
       "\"mapping\":{\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"color\":\"magenta\",\n",
       "\"position\":\"identity\",\n",
       "\"xintercept\":20.0,\n",
       "\"geom\":\"vline\",\n",
       "\"data\":{\n",
       "}\n",
       "},{\n",
       "\"mapping\":{\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"color\":\"dark_green\",\n",
       "\"position\":\"identity\",\n",
       "\"xintercept\":30.0,\n",
       "\"geom\":\"vline\",\n",
       "\"data\":{\n",
       "}\n",
       "}],\n",
       "\"mapping\":{\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[{\n",
       "\"aesthetic\":\"x\",\n",
       "\"limits\":[0.0,30.0]\n",
       "},{\n",
       "\"aesthetic\":\"y\",\n",
       "\"limits\":[0.0,20.0]\n",
       "}]\n",
       "},{\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"yintercept\":5.0,\n",
       "\"color\":\"red\",\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"hline\",\n",
       "\"data\":{\n",
       "}\n",
       "},{\n",
       "\"mapping\":{\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"yintercept\":10.0,\n",
       "\"color\":\"green\",\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"hline\",\n",
       "\"data\":{\n",
       "}\n",
       "},{\n",
       "\"mapping\":{\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"yintercept\":15.0,\n",
       "\"color\":\"blue\",\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"hline\",\n",
       "\"data\":{\n",
       "}\n",
       "},{\n",
       "\"mapping\":{\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"yintercept\":20.0,\n",
       "\"color\":\"orange\",\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"hline\",\n",
       "\"data\":{\n",
       "}\n",
       "},{\n",
       "\"mapping\":{\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"color\":\"pink\",\n",
       "\"position\":\"identity\",\n",
       "\"xintercept\":10.0,\n",
       "\"geom\":\"vline\",\n",
       "\"data\":{\n",
       "}\n",
       "},{\n",
       "\"mapping\":{\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"color\":\"magenta\",\n",
       "\"position\":\"identity\",\n",
       "\"xintercept\":20.0,\n",
       "\"geom\":\"vline\",\n",
       "\"data\":{\n",
       "}\n",
       "},{\n",
       "\"mapping\":{\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"color\":\"dark_green\",\n",
       "\"position\":\"identity\",\n",
       "\"xintercept\":30.0,\n",
       "\"geom\":\"vline\",\n",
       "\"data\":{\n",
       "}\n",
       "}],\n",
       "\"mapping\":{\n",
       "},\n",
       "\"coord\":{\n",
       "\"name\":\"polar\"\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[{\n",
       "\"aesthetic\":\"x\",\n",
       "\"limits\":[0.0,30.0]\n",
       "},{\n",
       "\"aesthetic\":\"y\",\n",
       "\"limits\":[0.0,20.0]\n",
       "}]\n",
       "}],\n",
       "\"kind\":\"subplots\"\n",
       "};\n",
       "           var plotContainer = document.getElementById(\"yDf20Q\");\n",
       "           window.letsPlotCall(function() {{\n",
       "               LetsPlot.buildPlotFromProcessedSpecs(plotSpec, -1, -1, plotContainer);\n",
       "           }});\n",
       "       })();\n",
       "   </script>"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "val p = letsPlot() +\n",
    "    geomHLine(yintercept = 5,  color = \"red\") +\n",
    "    geomHLine(yintercept = 10, color = \"green\") +\n",
    "    geomHLine(yintercept = 15, color = \"blue\") +\n",
    "    geomHLine(yintercept = 20, color = \"orange\") +\n",
    "    geomVLine(xintercept = 10, color = \"pink\") +\n",
    "    geomVLine(xintercept = 20, color = \"magenta\") +\n",
    "    geomVLine(xintercept = 30, color = \"dark_green\") +\n",
    "    xlim(0 to 30) +\n",
    "    ylim(0 to 20)\n",
    "    \n",
    "gggrid(listOf(p, p + coordPolar()))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "dc107ee4",
   "metadata": {},
   "source": [
    "## `geomTile()`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "4a7349b8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "   <div id=\"yjnFA5\"></div>\n",
       "   <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n",
       "       (function() {\n",
       "           var plotSpec={\n",
       "\"layout\":{\n",
       "\"name\":\"grid\",\n",
       "\"ncol\":2,\n",
       "\"nrow\":1,\n",
       "\"fit\":true,\n",
       "\"align\":false\n",
       "},\n",
       "\"theme\":{\n",
       "\"name\":\"grey\"\n",
       "},\n",
       "\"figures\":[{\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"tile\",\n",
       "\"data\":{\n",
       "}\n",
       "}],\n",
       "\"mapping\":{\n",
       "\"x\":\"x\",\n",
       "\"y\":\"y\",\n",
       "\"fill\":\"fill\"\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[{\n",
       "\"aesthetic\":\"fill\",\n",
       "\"scale_mapper_kind\":\"color_hue\"\n",
       "}],\n",
       "\"data\":{\n",
       "\"x\":[0.0,0.12,0.24,0.36,0.48,0.6,0.72,0.84,0.96,0.0,0.12,0.24,0.36,0.48,0.6,0.72,0.84,0.96,0.0,0.12,0.24,0.36,0.48,0.6,0.72,0.84,0.96,0.0,0.12,0.24,0.36,0.48,0.6,0.72,0.84,0.96,0.0,0.12,0.24,0.36,0.48,0.6,0.72,0.84,0.96,0.0,0.12,0.24,0.36,0.48,0.6,0.72,0.84,0.96,0.0,0.12,0.24,0.36,0.48,0.6,0.72,0.84,0.96],\n",
       "\"y\":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.15,0.15,0.15,0.15,0.15,0.15,0.15,0.15,0.15,0.3,0.3,0.3,0.3,0.3,0.3,0.3,0.3,0.3,0.44999999999999996,0.44999999999999996,0.44999999999999996,0.44999999999999996,0.44999999999999996,0.44999999999999996,0.44999999999999996,0.44999999999999996,0.44999999999999996,0.6,0.6,0.6,0.6,0.6,0.6,0.6,0.6,0.6,0.75,0.75,0.75,0.75,0.75,0.75,0.75,0.75,0.75,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9],\n",
       "\"fill\":[-0.8390715290764524,-0.8330374595617269,-0.8150214639187641,-0.7852549476461197,-0.7438112827472775,-0.6892215266032644,-0.6152810204151956,-0.5076308890007755,-0.34512535381544396,-0.8390715290764524,-0.8231810766885503,-0.7954740743570979,-0.7566296693349871,-0.7071698592703262,-0.6460632625930007,-0.5675196754338458,-0.4575597154025272,-0.2953707445915619,-0.8390715290764524,-0.8130579903474421,-0.7748958609848972,-0.7257985091939805,-0.6668617660117347,-0.597648753431217,-0.5129641562892151,-0.3994028388588531,-0.23668462968907183,-0.8390715290764524,-0.8026714803298189,-0.753313490286524,-0.6928513490416044,-0.6230958698730636,-0.5443698920072552,-0.45225018027885505,-0.3340823370639986,-0.17028182300992828,-0.8390715290764524,-0.7920249117740684,-0.7307549299936951,-0.657884239453171,-0.5760989552636295,-0.48665794587511463,-0.38608522714740445,-0.26263386704188557,-0.0975368754647962,-0.8390715290764524,-0.7811217340752652,-0.7072494128432085,-0.6209991197453719,-0.5261145489579291,-0.42498006634358393,-0.31524029506071427,-0.1861902447965802,-0.01995562150398114,-0.8390715290764524,-0.769965479767605,-0.6828273986954134,-0.5823035207934633,-0.47340165819811186,-0.3598355071040994,-0.2405409164209597,-0.10596348450643661,0.06085599194624228]\n",
       "}\n",
       "},{\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"tile\",\n",
       "\"data\":{\n",
       "}\n",
       "}],\n",
       "\"mapping\":{\n",
       "\"x\":\"x\",\n",
       "\"y\":\"y\",\n",
       "\"fill\":\"fill\"\n",
       "},\n",
       "\"coord\":{\n",
       "\"name\":\"polar\",\n",
       "\"ylim\":[-0.5,null]\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[{\n",
       "\"aesthetic\":\"fill\",\n",
       "\"scale_mapper_kind\":\"color_hue\"\n",
       "}],\n",
       "\"data\":{\n",
       "\"x\":[0.0,0.12,0.24,0.36,0.48,0.6,0.72,0.84,0.96,0.0,0.12,0.24,0.36,0.48,0.6,0.72,0.84,0.96,0.0,0.12,0.24,0.36,0.48,0.6,0.72,0.84,0.96,0.0,0.12,0.24,0.36,0.48,0.6,0.72,0.84,0.96,0.0,0.12,0.24,0.36,0.48,0.6,0.72,0.84,0.96,0.0,0.12,0.24,0.36,0.48,0.6,0.72,0.84,0.96,0.0,0.12,0.24,0.36,0.48,0.6,0.72,0.84,0.96],\n",
       "\"y\":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.15,0.15,0.15,0.15,0.15,0.15,0.15,0.15,0.15,0.3,0.3,0.3,0.3,0.3,0.3,0.3,0.3,0.3,0.44999999999999996,0.44999999999999996,0.44999999999999996,0.44999999999999996,0.44999999999999996,0.44999999999999996,0.44999999999999996,0.44999999999999996,0.44999999999999996,0.6,0.6,0.6,0.6,0.6,0.6,0.6,0.6,0.6,0.75,0.75,0.75,0.75,0.75,0.75,0.75,0.75,0.75,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9],\n",
       "\"fill\":[-0.8390715290764524,-0.8330374595617269,-0.8150214639187641,-0.7852549476461197,-0.7438112827472775,-0.6892215266032644,-0.6152810204151956,-0.5076308890007755,-0.34512535381544396,-0.8390715290764524,-0.8231810766885503,-0.7954740743570979,-0.7566296693349871,-0.7071698592703262,-0.6460632625930007,-0.5675196754338458,-0.4575597154025272,-0.2953707445915619,-0.8390715290764524,-0.8130579903474421,-0.7748958609848972,-0.7257985091939805,-0.6668617660117347,-0.597648753431217,-0.5129641562892151,-0.3994028388588531,-0.23668462968907183,-0.8390715290764524,-0.8026714803298189,-0.753313490286524,-0.6928513490416044,-0.6230958698730636,-0.5443698920072552,-0.45225018027885505,-0.3340823370639986,-0.17028182300992828,-0.8390715290764524,-0.7920249117740684,-0.7307549299936951,-0.657884239453171,-0.5760989552636295,-0.48665794587511463,-0.38608522714740445,-0.26263386704188557,-0.0975368754647962,-0.8390715290764524,-0.7811217340752652,-0.7072494128432085,-0.6209991197453719,-0.5261145489579291,-0.42498006634358393,-0.31524029506071427,-0.1861902447965802,-0.01995562150398114,-0.8390715290764524,-0.769965479767605,-0.6828273986954134,-0.5823035207934633,-0.47340165819811186,-0.3598355071040994,-0.2405409164209597,-0.10596348450643661,0.06085599194624228]\n",
       "}\n",
       "}],\n",
       "\"kind\":\"subplots\"\n",
       "};\n",
       "           var plotContainer = document.getElementById(\"yjnFA5\");\n",
       "           window.letsPlotCall(function() {{\n",
       "               LetsPlot.buildPlotFromProcessedSpecs(plotSpec, -1, -1, plotContainer);\n",
       "           }});\n",
       "       })();\n",
       "   </script>"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "fun meshgridPoints(x:List<Double>, y:List<Double>):List<Pair<Double, Double>> {\n",
    "  val xSer = y.flatMap { x }\n",
    "  var yInd = -1\n",
    "  val ySer = y.flatMap { \n",
    "      yInd++\n",
    "      List(x.size) {y[yInd]} \n",
    "  }\n",
    "  return xSer.zip(ySer)\n",
    "}\n",
    "\n",
    "val gridPoints = meshgridPoints(\n",
    "    generateSequence(0.0, {it + 6.0/50} ).takeWhile { it <= 1.0 }.toList(),\n",
    "    generateSequence(0.0, {it + 6.0/40} ).takeWhile { it <= 1.0 }.toList())\n",
    "fun f(x:Double, y:Double): Double {\n",
    "    return sin(x).pow(10) + cos(10 + y * x) * cos(x)\n",
    "}\n",
    "\n",
    "val X = gridPoints.map { it.first }\n",
    "val Y = gridPoints.map { it.second }\n",
    "val Z = gridPoints.map { f(it.first, it.second) }\n",
    "\n",
    "val p = letsPlot {x=X; y=Y; fill=Z} + geomTile() + scaleFillHue()\n",
    "\n",
    "gggrid(listOf(\n",
    "    p,\n",
    "    p + coordPolar(ylim = -0.5 to null)  // ylim to make a hole\n",
    "\n",
    "))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3a56f044",
   "metadata": {},
   "source": [
    "## `geomRect()`"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "da9e662a",
   "metadata": {},
   "source": [
    "### Stacked bars\n",
    "are transformed into a pie chart"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "0debeeb6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "   <div id=\"W6Ip2r\"></div>\n",
       "   <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n",
       "       (function() {\n",
       "           var plotSpec={\n",
       "\"layout\":{\n",
       "\"name\":\"grid\",\n",
       "\"ncol\":3,\n",
       "\"nrow\":1,\n",
       "\"fit\":true,\n",
       "\"align\":false\n",
       "},\n",
       "\"theme\":{\n",
       "\"name\":\"grey\"\n",
       "},\n",
       "\"figures\":[{\n",
       "\"layers\":[{\n",
       "\"ymin\":0.0,\n",
       "\"mapping\":{\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"xmin\":0.0,\n",
       "\"ymax\":7.0,\n",
       "\"xmax\":5.0,\n",
       "\"size\":0.0,\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"rect\",\n",
       "\"fill\":\"#66c2a5\",\n",
       "\"data\":{\n",
       "}\n",
       "},{\n",
       "\"ymin\":7.0,\n",
       "\"mapping\":{\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"xmin\":0.0,\n",
       "\"ymax\":11.0,\n",
       "\"xmax\":5.0,\n",
       "\"size\":0.0,\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"rect\",\n",
       "\"fill\":\"#fc8d62\",\n",
       "\"data\":{\n",
       "}\n",
       "},{\n",
       "\"ymin\":11.0,\n",
       "\"mapping\":{\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"xmin\":0.0,\n",
       "\"ymax\":14.0,\n",
       "\"xmax\":5.0,\n",
       "\"size\":0.0,\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"rect\",\n",
       "\"fill\":\"#8da0cb\",\n",
       "\"data\":{\n",
       "}\n",
       "}],\n",
       "\"mapping\":{\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[]\n",
       "},{\n",
       "\"ggtitle\":{\n",
       "\"text\":\"coordPolar()\"\n",
       "},\n",
       "\"mapping\":{\n",
       "},\n",
       "\"coord\":{\n",
       "\"name\":\"polar\"\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[],\n",
       "\"layers\":[{\n",
       "\"ymin\":0.0,\n",
       "\"mapping\":{\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"xmin\":0.0,\n",
       "\"ymax\":7.0,\n",
       "\"xmax\":5.0,\n",
       "\"size\":0.0,\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"rect\",\n",
       "\"fill\":\"#66c2a5\",\n",
       "\"data\":{\n",
       "}\n",
       "},{\n",
       "\"ymin\":7.0,\n",
       "\"mapping\":{\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"xmin\":0.0,\n",
       "\"ymax\":11.0,\n",
       "\"xmax\":5.0,\n",
       "\"size\":0.0,\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"rect\",\n",
       "\"fill\":\"#fc8d62\",\n",
       "\"data\":{\n",
       "}\n",
       "},{\n",
       "\"ymin\":11.0,\n",
       "\"mapping\":{\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"xmin\":0.0,\n",
       "\"ymax\":14.0,\n",
       "\"xmax\":5.0,\n",
       "\"size\":0.0,\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"rect\",\n",
       "\"fill\":\"#8da0cb\",\n",
       "\"data\":{\n",
       "}\n",
       "}]\n",
       "},{\n",
       "\"ggtitle\":{\n",
       "\"text\":\"coordPolar(theta=y)\"\n",
       "},\n",
       "\"mapping\":{\n",
       "},\n",
       "\"coord\":{\n",
       "\"name\":\"polar\",\n",
       "\"theta\":\"y\"\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[],\n",
       "\"layers\":[{\n",
       "\"ymin\":0.0,\n",
       "\"mapping\":{\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"xmin\":0.0,\n",
       "\"ymax\":7.0,\n",
       "\"xmax\":5.0,\n",
       "\"size\":0.0,\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"rect\",\n",
       "\"fill\":\"#66c2a5\",\n",
       "\"data\":{\n",
       "}\n",
       "},{\n",
       "\"ymin\":7.0,\n",
       "\"mapping\":{\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"xmin\":0.0,\n",
       "\"ymax\":11.0,\n",
       "\"xmax\":5.0,\n",
       "\"size\":0.0,\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"rect\",\n",
       "\"fill\":\"#fc8d62\",\n",
       "\"data\":{\n",
       "}\n",
       "},{\n",
       "\"ymin\":11.0,\n",
       "\"mapping\":{\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"xmin\":0.0,\n",
       "\"ymax\":14.0,\n",
       "\"xmax\":5.0,\n",
       "\"size\":0.0,\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"rect\",\n",
       "\"fill\":\"#8da0cb\",\n",
       "\"data\":{\n",
       "}\n",
       "}]\n",
       "}],\n",
       "\"kind\":\"subplots\"\n",
       "};\n",
       "           var plotContainer = document.getElementById(\"W6Ip2r\");\n",
       "           window.letsPlotCall(function() {{\n",
       "               LetsPlot.buildPlotFromProcessedSpecs(plotSpec, -1, -1, plotContainer);\n",
       "           }});\n",
       "       })();\n",
       "   </script>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "   <div id=\"OUYwj8\"></div>\n",
       "   <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n",
       "       (function() {\n",
       "           var plotSpec={\n",
       "\"layout\":{\n",
       "\"name\":\"grid\",\n",
       "\"ncol\":2,\n",
       "\"nrow\":1,\n",
       "\"fit\":true,\n",
       "\"align\":false\n",
       "},\n",
       "\"theme\":{\n",
       "\"name\":\"grey\"\n",
       "},\n",
       "\"figures\":[{\n",
       "\"ggtitle\":{\n",
       "\"text\":\"coordPolar(theta=y, dir=-1)\"\n",
       "},\n",
       "\"mapping\":{\n",
       "},\n",
       "\"coord\":{\n",
       "\"name\":\"polar\",\n",
       "\"theta\":\"y\",\n",
       "\"direction\":-1.0\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[],\n",
       "\"layers\":[{\n",
       "\"ymin\":0.0,\n",
       "\"mapping\":{\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"xmin\":0.0,\n",
       "\"ymax\":7.0,\n",
       "\"xmax\":5.0,\n",
       "\"size\":0.0,\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"rect\",\n",
       "\"fill\":\"#66c2a5\",\n",
       "\"data\":{\n",
       "}\n",
       "},{\n",
       "\"ymin\":7.0,\n",
       "\"mapping\":{\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"xmin\":0.0,\n",
       "\"ymax\":11.0,\n",
       "\"xmax\":5.0,\n",
       "\"size\":0.0,\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"rect\",\n",
       "\"fill\":\"#fc8d62\",\n",
       "\"data\":{\n",
       "}\n",
       "},{\n",
       "\"ymin\":11.0,\n",
       "\"mapping\":{\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"xmin\":0.0,\n",
       "\"ymax\":14.0,\n",
       "\"xmax\":5.0,\n",
       "\"size\":0.0,\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"rect\",\n",
       "\"fill\":\"#8da0cb\",\n",
       "\"data\":{\n",
       "}\n",
       "}]\n",
       "},{\n",
       "\"ggtitle\":{\n",
       "\"text\":\"coordPolar(theta=y, dir=-1, start=PI/2)\"\n",
       "},\n",
       "\"mapping\":{\n",
       "},\n",
       "\"coord\":{\n",
       "\"name\":\"polar\",\n",
       "\"start\":1.57,\n",
       "\"theta\":\"y\",\n",
       "\"direction\":-1.0\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[],\n",
       "\"layers\":[{\n",
       "\"ymin\":0.0,\n",
       "\"mapping\":{\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"xmin\":0.0,\n",
       "\"ymax\":7.0,\n",
       "\"xmax\":5.0,\n",
       "\"size\":0.0,\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"rect\",\n",
       "\"fill\":\"#66c2a5\",\n",
       "\"data\":{\n",
       "}\n",
       "},{\n",
       "\"ymin\":7.0,\n",
       "\"mapping\":{\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"xmin\":0.0,\n",
       "\"ymax\":11.0,\n",
       "\"xmax\":5.0,\n",
       "\"size\":0.0,\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"rect\",\n",
       "\"fill\":\"#fc8d62\",\n",
       "\"data\":{\n",
       "}\n",
       "},{\n",
       "\"ymin\":11.0,\n",
       "\"mapping\":{\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"xmin\":0.0,\n",
       "\"ymax\":14.0,\n",
       "\"xmax\":5.0,\n",
       "\"size\":0.0,\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"rect\",\n",
       "\"fill\":\"#8da0cb\",\n",
       "\"data\":{\n",
       "}\n",
       "}]\n",
       "}],\n",
       "\"kind\":\"subplots\"\n",
       "};\n",
       "           var plotContainer = document.getElementById(\"OUYwj8\");\n",
       "           window.letsPlotCall(function() {{\n",
       "               LetsPlot.buildPlotFromProcessedSpecs(plotSpec, -1, -1, plotContainer);\n",
       "           }});\n",
       "       })();\n",
       "   </script>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "val c1 = \"#66c2a5\"\n",
    "val c2 = \"#fc8d62\"\n",
    "val c3 = \"#8da0cb\"\n",
    "val p = ggplot() + \n",
    "    geomRect(xmin=0, xmax=5, ymin=0, ymax=7, fill=c1, size=0) +\n",
    "    geomRect(xmin=0, xmax=5, ymin=7, ymax=11, fill=c2, size=0) +\n",
    "    geomRect(xmin=0, xmax=5, ymin=11, ymax=14, fill=c3, size=0) \n",
    "\n",
    "gggrid(listOf(\n",
    "    p,\n",
    "    p + coordPolar() + ggtitle(\"coordPolar()\"),\n",
    "    p + coordPolar(theta = \"y\") + ggtitle(\"coordPolar(theta=y)\"),\n",
    ")).show()\n",
    "\n",
    "gggrid(listOf(\n",
    "    p + coordPolar(theta = \"y\", direction = -1) + ggtitle(\"coordPolar(theta=y, dir=-1)\"),\n",
    "    p + coordPolar(theta = \"y\", direction = -1, start = 3.14/2) + \n",
    "        ggtitle(\"coordPolar(theta=y, dir=-1, start=PI/2)\"),\n",
    ")).show()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c3ddc05c",
   "metadata": {},
   "source": [
    "### Dodged bars"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "4c7e6d24",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "   <div id=\"nOwjos\"></div>\n",
       "   <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n",
       "       (function() {\n",
       "           var plotSpec={\n",
       "\"layout\":{\n",
       "\"name\":\"grid\",\n",
       "\"ncol\":3,\n",
       "\"nrow\":1,\n",
       "\"fit\":true,\n",
       "\"align\":false\n",
       "},\n",
       "\"theme\":{\n",
       "\"name\":\"grey\"\n",
       "},\n",
       "\"figures\":[{\n",
       "\"layers\":[{\n",
       "\"ymin\":0.0,\n",
       "\"mapping\":{\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"xmin\":0.0,\n",
       "\"ymax\":7.0,\n",
       "\"xmax\":1.0,\n",
       "\"size\":0.0,\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"rect\",\n",
       "\"fill\":\"#66c2a5\",\n",
       "\"data\":{\n",
       "}\n",
       "},{\n",
       "\"ymin\":0.0,\n",
       "\"mapping\":{\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"xmin\":1.0,\n",
       "\"ymax\":4.0,\n",
       "\"xmax\":2.0,\n",
       "\"size\":0.0,\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"rect\",\n",
       "\"fill\":\"#fc8d62\",\n",
       "\"data\":{\n",
       "}\n",
       "},{\n",
       "\"ymin\":0.0,\n",
       "\"mapping\":{\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"xmin\":2.0,\n",
       "\"ymax\":3.0,\n",
       "\"xmax\":3.0,\n",
       "\"size\":0.0,\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"rect\",\n",
       "\"fill\":\"#8da0cb\",\n",
       "\"data\":{\n",
       "}\n",
       "}],\n",
       "\"mapping\":{\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[]\n",
       "},{\n",
       "\"ggtitle\":{\n",
       "\"text\":\"coordPolar(theta=y)\"\n",
       "},\n",
       "\"mapping\":{\n",
       "},\n",
       "\"coord\":{\n",
       "\"name\":\"polar\",\n",
       "\"theta\":\"y\"\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[],\n",
       "\"layers\":[{\n",
       "\"ymin\":0.0,\n",
       "\"mapping\":{\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"xmin\":0.0,\n",
       "\"ymax\":7.0,\n",
       "\"xmax\":1.0,\n",
       "\"size\":0.0,\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"rect\",\n",
       "\"fill\":\"#66c2a5\",\n",
       "\"data\":{\n",
       "}\n",
       "},{\n",
       "\"ymin\":0.0,\n",
       "\"mapping\":{\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"xmin\":1.0,\n",
       "\"ymax\":4.0,\n",
       "\"xmax\":2.0,\n",
       "\"size\":0.0,\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"rect\",\n",
       "\"fill\":\"#fc8d62\",\n",
       "\"data\":{\n",
       "}\n",
       "},{\n",
       "\"ymin\":0.0,\n",
       "\"mapping\":{\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"xmin\":2.0,\n",
       "\"ymax\":3.0,\n",
       "\"xmax\":3.0,\n",
       "\"size\":0.0,\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"rect\",\n",
       "\"fill\":\"#8da0cb\",\n",
       "\"data\":{\n",
       "}\n",
       "}]\n",
       "},{\n",
       "\"ggtitle\":{\n",
       "\"text\":\"coordPolar(theta=x)\"\n",
       "},\n",
       "\"mapping\":{\n",
       "},\n",
       "\"coord\":{\n",
       "\"name\":\"polar\",\n",
       "\"theta\":\"x\"\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[],\n",
       "\"layers\":[{\n",
       "\"ymin\":0.0,\n",
       "\"mapping\":{\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"xmin\":0.0,\n",
       "\"ymax\":7.0,\n",
       "\"xmax\":1.0,\n",
       "\"size\":0.0,\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"rect\",\n",
       "\"fill\":\"#66c2a5\",\n",
       "\"data\":{\n",
       "}\n",
       "},{\n",
       "\"ymin\":0.0,\n",
       "\"mapping\":{\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"xmin\":1.0,\n",
       "\"ymax\":4.0,\n",
       "\"xmax\":2.0,\n",
       "\"size\":0.0,\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"rect\",\n",
       "\"fill\":\"#fc8d62\",\n",
       "\"data\":{\n",
       "}\n",
       "},{\n",
       "\"ymin\":0.0,\n",
       "\"mapping\":{\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"xmin\":2.0,\n",
       "\"ymax\":3.0,\n",
       "\"xmax\":3.0,\n",
       "\"size\":0.0,\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"rect\",\n",
       "\"fill\":\"#8da0cb\",\n",
       "\"data\":{\n",
       "}\n",
       "}]\n",
       "}],\n",
       "\"kind\":\"subplots\"\n",
       "};\n",
       "           var plotContainer = document.getElementById(\"nOwjos\");\n",
       "           window.letsPlotCall(function() {{\n",
       "               LetsPlot.buildPlotFromProcessedSpecs(plotSpec, -1, -1, plotContainer);\n",
       "           }});\n",
       "       })();\n",
       "   </script>"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "val p = letsPlot() +\n",
    "    geomRect(xmin=0, xmax=1, ymin=0, ymax=7, fill=c1, size=0) +\n",
    "    geomRect(xmin=1, xmax=2, ymin=0, ymax=4, fill=c2, size=0) +\n",
    "    geomRect(xmin=2, xmax=3, ymin=0, ymax=3, fill=c3, size=0)\n",
    "\n",
    "gggrid(listOf(\n",
    "    p, \n",
    "    p + coordPolar(theta = \"y\") + ggtitle(\"coordPolar(theta=y)\"),\n",
    "    p + coordPolar(theta = \"x\") + ggtitle(\"coordPolar(theta=x)\"),\n",
    "))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1cdc326c",
   "metadata": {},
   "source": [
    "### Horizontal bars"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "20755414",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "   <div id=\"sx0dzz\"></div>\n",
       "   <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n",
       "       (function() {\n",
       "           var plotSpec={\n",
       "\"layout\":{\n",
       "\"name\":\"grid\",\n",
       "\"ncol\":3,\n",
       "\"nrow\":1,\n",
       "\"fit\":true,\n",
       "\"align\":false\n",
       "},\n",
       "\"theme\":{\n",
       "\"name\":\"grey\"\n",
       "},\n",
       "\"figures\":[{\n",
       "\"layers\":[{\n",
       "\"ymin\":0.0,\n",
       "\"mapping\":{\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"xmin\":0.0,\n",
       "\"ymax\":1.0,\n",
       "\"xmax\":7.0,\n",
       "\"size\":0.0,\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"rect\",\n",
       "\"fill\":\"#66c2a5\",\n",
       "\"data\":{\n",
       "}\n",
       "},{\n",
       "\"ymin\":1.0,\n",
       "\"mapping\":{\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"xmin\":0.0,\n",
       "\"ymax\":2.0,\n",
       "\"xmax\":4.0,\n",
       "\"size\":0.0,\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"rect\",\n",
       "\"fill\":\"#fc8d62\",\n",
       "\"data\":{\n",
       "}\n",
       "},{\n",
       "\"ymin\":2.0,\n",
       "\"mapping\":{\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"xmin\":0.0,\n",
       "\"ymax\":3.0,\n",
       "\"xmax\":3.0,\n",
       "\"size\":0.0,\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"rect\",\n",
       "\"fill\":\"#8da0cb\",\n",
       "\"data\":{\n",
       "}\n",
       "}],\n",
       "\"mapping\":{\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[]\n",
       "},{\n",
       "\"ggtitle\":{\n",
       "\"text\":\"coordPolar(theta=y)\"\n",
       "},\n",
       "\"mapping\":{\n",
       "},\n",
       "\"coord\":{\n",
       "\"name\":\"polar\",\n",
       "\"theta\":\"y\"\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[],\n",
       "\"layers\":[{\n",
       "\"ymin\":0.0,\n",
       "\"mapping\":{\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"xmin\":0.0,\n",
       "\"ymax\":1.0,\n",
       "\"xmax\":7.0,\n",
       "\"size\":0.0,\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"rect\",\n",
       "\"fill\":\"#66c2a5\",\n",
       "\"data\":{\n",
       "}\n",
       "},{\n",
       "\"ymin\":1.0,\n",
       "\"mapping\":{\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"xmin\":0.0,\n",
       "\"ymax\":2.0,\n",
       "\"xmax\":4.0,\n",
       "\"size\":0.0,\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"rect\",\n",
       "\"fill\":\"#fc8d62\",\n",
       "\"data\":{\n",
       "}\n",
       "},{\n",
       "\"ymin\":2.0,\n",
       "\"mapping\":{\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"xmin\":0.0,\n",
       "\"ymax\":3.0,\n",
       "\"xmax\":3.0,\n",
       "\"size\":0.0,\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"rect\",\n",
       "\"fill\":\"#8da0cb\",\n",
       "\"data\":{\n",
       "}\n",
       "}]\n",
       "},{\n",
       "\"ggtitle\":{\n",
       "\"text\":\"coordPolar(theta=x)\"\n",
       "},\n",
       "\"mapping\":{\n",
       "},\n",
       "\"coord\":{\n",
       "\"name\":\"polar\",\n",
       "\"theta\":\"x\"\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[],\n",
       "\"layers\":[{\n",
       "\"ymin\":0.0,\n",
       "\"mapping\":{\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"xmin\":0.0,\n",
       "\"ymax\":1.0,\n",
       "\"xmax\":7.0,\n",
       "\"size\":0.0,\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"rect\",\n",
       "\"fill\":\"#66c2a5\",\n",
       "\"data\":{\n",
       "}\n",
       "},{\n",
       "\"ymin\":1.0,\n",
       "\"mapping\":{\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"xmin\":0.0,\n",
       "\"ymax\":2.0,\n",
       "\"xmax\":4.0,\n",
       "\"size\":0.0,\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"rect\",\n",
       "\"fill\":\"#fc8d62\",\n",
       "\"data\":{\n",
       "}\n",
       "},{\n",
       "\"ymin\":2.0,\n",
       "\"mapping\":{\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"xmin\":0.0,\n",
       "\"ymax\":3.0,\n",
       "\"xmax\":3.0,\n",
       "\"size\":0.0,\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"rect\",\n",
       "\"fill\":\"#8da0cb\",\n",
       "\"data\":{\n",
       "}\n",
       "}]\n",
       "}],\n",
       "\"kind\":\"subplots\"\n",
       "};\n",
       "           var plotContainer = document.getElementById(\"sx0dzz\");\n",
       "           window.letsPlotCall(function() {{\n",
       "               LetsPlot.buildPlotFromProcessedSpecs(plotSpec, -1, -1, plotContainer);\n",
       "           }});\n",
       "       })();\n",
       "   </script>"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "val p = letsPlot() +\n",
    "    geomRect(ymin=0, ymax=1, xmin=0, xmax=7, fill=c1, size=0) +\n",
    "    geomRect(ymin=1, ymax=2, xmin=0, xmax=4, fill=c2, size=0) +\n",
    "    geomRect(ymin=2, ymax=3, xmin=0, xmax=3, fill=c3, size=0)\n",
    "\n",
    "gggrid(listOf(\n",
    "    p, \n",
    "    p + coordPolar(theta = \"y\") + ggtitle(\"coordPolar(theta=y)\"),\n",
    "    p + coordPolar(theta = \"x\") + ggtitle(\"coordPolar(theta=x)\"),\n",
    "))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7377309b",
   "metadata": {},
   "source": [
    "# Params"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "a72b8335",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "   <div id=\"jbMFkc\"></div>\n",
       "   <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n",
       "       (function() {\n",
       "           var plotSpec={\n",
       "\"ggtitle\":{\n",
       "\"text\":\"Default plot with coordPolar()\"\n",
       "},\n",
       "\"mapping\":{\n",
       "\"x\":\"x\",\n",
       "\"y\":\"y\",\n",
       "\"color\":\"y\"\n",
       "},\n",
       "\"coord\":{\n",
       "\"name\":\"polar\"\n",
       "},\n",
       "\"data\":{\n",
       "\"x\":[0.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0],\n",
       "\"y\":[0.0,45.0,90.0,135.0,180.0,225.0,270.0,315.0,360.0]\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[{\n",
       "\"aesthetic\":\"color\",\n",
       "\"scale_mapper_kind\":\"color_brewer\",\n",
       "\"palette\":\"GnBu\"\n",
       "}],\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"size\":3.0,\n",
       "\"show_legend\":false,\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"path\",\n",
       "\"data\":{\n",
       "}\n",
       "}],\n",
       "\"theme\":{\n",
       "\"name\":\"grey\"\n",
       "}\n",
       "};\n",
       "           var plotContainer = document.getElementById(\"jbMFkc\");\n",
       "           window.letsPlotCall(function() {{\n",
       "               LetsPlot.buildPlotFromProcessedSpecs(plotSpec, -1, -1, plotContainer);\n",
       "           }});\n",
       "       })();\n",
       "   </script>"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "val p = letsPlot(labelsData) { x = \"x\"; y = \"y\"; color = \"y\" } + \n",
    "    geomPath(size = 3, showLegend = false) + \n",
    "    scaleColorBrewer(palette = \"GnBu\")\n",
    "\n",
    "\n",
    "p + coordPolar() + ggtitle(\"Default plot with coordPolar()\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "666e916a",
   "metadata": {},
   "source": [
    "### `transformBkgr`  \n",
    "\n",
    "When using the `transformBkgr` parameter, the panel is not transformed into a circle, but remains a rectangle. This behaviour is similar to `ggplot2`."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "2d5572bd",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "   <div id=\"6APXT6\"></div>\n",
       "   <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n",
       "       (function() {\n",
       "           var plotSpec={\n",
       "\"ggtitle\":{\n",
       "\"text\":\"coordPolar(transformBkgr=false)\"\n",
       "},\n",
       "\"mapping\":{\n",
       "\"x\":\"x\",\n",
       "\"y\":\"y\",\n",
       "\"color\":\"y\"\n",
       "},\n",
       "\"coord\":{\n",
       "\"name\":\"polar\",\n",
       "\"transform_bkgr\":false\n",
       "},\n",
       "\"data\":{\n",
       "\"x\":[0.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0],\n",
       "\"y\":[0.0,45.0,90.0,135.0,180.0,225.0,270.0,315.0,360.0]\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[{\n",
       "\"aesthetic\":\"color\",\n",
       "\"scale_mapper_kind\":\"color_brewer\",\n",
       "\"palette\":\"GnBu\"\n",
       "}],\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"size\":3.0,\n",
       "\"show_legend\":false,\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"path\",\n",
       "\"data\":{\n",
       "}\n",
       "}],\n",
       "\"theme\":{\n",
       "\"name\":\"grey\"\n",
       "}\n",
       "};\n",
       "           var plotContainer = document.getElementById(\"6APXT6\");\n",
       "           window.letsPlotCall(function() {{\n",
       "               LetsPlot.buildPlotFromProcessedSpecs(plotSpec, -1, -1, plotContainer);\n",
       "           }});\n",
       "       })();\n",
       "   </script>"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "p + coordPolar(transformBkgr = false) + ggtitle(\"coordPolar(transformBkgr=false)\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6443e8f5",
   "metadata": {},
   "source": [
    "### `direction`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "66cbe28c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "   <div id=\"jpGHWs\"></div>\n",
       "   <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n",
       "       (function() {\n",
       "           var plotSpec={\n",
       "\"ggtitle\":{\n",
       "\"text\":\"coordPolar(direction=-1)\"\n",
       "},\n",
       "\"mapping\":{\n",
       "\"x\":\"x\",\n",
       "\"y\":\"y\",\n",
       "\"color\":\"y\"\n",
       "},\n",
       "\"coord\":{\n",
       "\"name\":\"polar\",\n",
       "\"direction\":-1.0\n",
       "},\n",
       "\"data\":{\n",
       "\"x\":[0.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0],\n",
       "\"y\":[0.0,45.0,90.0,135.0,180.0,225.0,270.0,315.0,360.0]\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[{\n",
       "\"aesthetic\":\"color\",\n",
       "\"scale_mapper_kind\":\"color_brewer\",\n",
       "\"palette\":\"GnBu\"\n",
       "}],\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"size\":3.0,\n",
       "\"show_legend\":false,\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"path\",\n",
       "\"data\":{\n",
       "}\n",
       "}],\n",
       "\"theme\":{\n",
       "\"name\":\"grey\"\n",
       "}\n",
       "};\n",
       "           var plotContainer = document.getElementById(\"jpGHWs\");\n",
       "           window.letsPlotCall(function() {{\n",
       "               LetsPlot.buildPlotFromProcessedSpecs(plotSpec, -1, -1, plotContainer);\n",
       "           }});\n",
       "       })();\n",
       "   </script>"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "p + coordPolar(direction = -1) + ggtitle(\"coordPolar(direction=-1)\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7dff898f",
   "metadata": {},
   "source": [
    "### `start`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "f5619d05",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "   <div id=\"ASUPVa\"></div>\n",
       "   <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n",
       "       (function() {\n",
       "           var plotSpec={\n",
       "\"layout\":{\n",
       "\"name\":\"grid\",\n",
       "\"ncol\":2,\n",
       "\"nrow\":1,\n",
       "\"fit\":true,\n",
       "\"align\":false\n",
       "},\n",
       "\"theme\":{\n",
       "\"name\":\"grey\"\n",
       "},\n",
       "\"figures\":[{\n",
       "\"ggtitle\":{\n",
       "\"text\":\"start=PI/2\"\n",
       "},\n",
       "\"mapping\":{\n",
       "\"x\":\"x\",\n",
       "\"y\":\"y\",\n",
       "\"color\":\"y\"\n",
       "},\n",
       "\"coord\":{\n",
       "\"name\":\"polar\",\n",
       "\"start\":1.57\n",
       "},\n",
       "\"data\":{\n",
       "\"x\":[0.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0],\n",
       "\"y\":[0.0,45.0,90.0,135.0,180.0,225.0,270.0,315.0,360.0]\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[{\n",
       "\"aesthetic\":\"color\",\n",
       "\"scale_mapper_kind\":\"color_brewer\",\n",
       "\"palette\":\"GnBu\"\n",
       "}],\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"size\":3.0,\n",
       "\"show_legend\":false,\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"path\",\n",
       "\"data\":{\n",
       "}\n",
       "}]\n",
       "},{\n",
       "\"ggtitle\":{\n",
       "\"text\":\"start=-PI/2\"\n",
       "},\n",
       "\"mapping\":{\n",
       "\"x\":\"x\",\n",
       "\"y\":\"y\",\n",
       "\"color\":\"y\"\n",
       "},\n",
       "\"coord\":{\n",
       "\"name\":\"polar\",\n",
       "\"start\":-1.57\n",
       "},\n",
       "\"data\":{\n",
       "\"x\":[0.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0],\n",
       "\"y\":[0.0,45.0,90.0,135.0,180.0,225.0,270.0,315.0,360.0]\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[{\n",
       "\"aesthetic\":\"color\",\n",
       "\"scale_mapper_kind\":\"color_brewer\",\n",
       "\"palette\":\"GnBu\"\n",
       "}],\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"size\":3.0,\n",
       "\"show_legend\":false,\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"path\",\n",
       "\"data\":{\n",
       "}\n",
       "}]\n",
       "}],\n",
       "\"kind\":\"subplots\"\n",
       "};\n",
       "           var plotContainer = document.getElementById(\"ASUPVa\");\n",
       "           window.letsPlotCall(function() {{\n",
       "               LetsPlot.buildPlotFromProcessedSpecs(plotSpec, -1, -1, plotContainer);\n",
       "           }});\n",
       "       })();\n",
       "   </script>"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "gggrid(listOf(\n",
    "    p + coordPolar(start = 3.14 / 2) + ggtitle(\"start=PI/2\"),\n",
    "    p + coordPolar(start = -3.14 / 2) + ggtitle(\"start=-PI/2\"),\n",
    "))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e3b202e6",
   "metadata": {},
   "source": [
    "### `direction` + `start`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "c21555ea",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "   <div id=\"jY1cUg\"></div>\n",
       "   <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n",
       "       (function() {\n",
       "           var plotSpec={\n",
       "\"layout\":{\n",
       "\"name\":\"grid\",\n",
       "\"ncol\":2,\n",
       "\"nrow\":1,\n",
       "\"fit\":true,\n",
       "\"align\":false\n",
       "},\n",
       "\"theme\":{\n",
       "\"name\":\"grey\"\n",
       "},\n",
       "\"figures\":[{\n",
       "\"ggtitle\":{\n",
       "\"text\":\"dir=-1, start=PI/2\"\n",
       "},\n",
       "\"mapping\":{\n",
       "\"x\":\"x\",\n",
       "\"y\":\"y\",\n",
       "\"color\":\"y\"\n",
       "},\n",
       "\"coord\":{\n",
       "\"name\":\"polar\",\n",
       "\"start\":1.57,\n",
       "\"direction\":-1.0\n",
       "},\n",
       "\"data\":{\n",
       "\"x\":[0.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0],\n",
       "\"y\":[0.0,45.0,90.0,135.0,180.0,225.0,270.0,315.0,360.0]\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[{\n",
       "\"aesthetic\":\"color\",\n",
       "\"scale_mapper_kind\":\"color_brewer\",\n",
       "\"palette\":\"GnBu\"\n",
       "}],\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"size\":3.0,\n",
       "\"show_legend\":false,\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"path\",\n",
       "\"data\":{\n",
       "}\n",
       "}]\n",
       "},{\n",
       "\"ggtitle\":{\n",
       "\"text\":\"dir=-1, start=-PI/2\"\n",
       "},\n",
       "\"mapping\":{\n",
       "\"x\":\"x\",\n",
       "\"y\":\"y\",\n",
       "\"color\":\"y\"\n",
       "},\n",
       "\"coord\":{\n",
       "\"name\":\"polar\",\n",
       "\"start\":-1.57,\n",
       "\"direction\":-1.0\n",
       "},\n",
       "\"data\":{\n",
       "\"x\":[0.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0],\n",
       "\"y\":[0.0,45.0,90.0,135.0,180.0,225.0,270.0,315.0,360.0]\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[{\n",
       "\"aesthetic\":\"color\",\n",
       "\"scale_mapper_kind\":\"color_brewer\",\n",
       "\"palette\":\"GnBu\"\n",
       "}],\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"size\":3.0,\n",
       "\"show_legend\":false,\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"path\",\n",
       "\"data\":{\n",
       "}\n",
       "}]\n",
       "}],\n",
       "\"kind\":\"subplots\"\n",
       "};\n",
       "           var plotContainer = document.getElementById(\"jY1cUg\");\n",
       "           window.letsPlotCall(function() {{\n",
       "               LetsPlot.buildPlotFromProcessedSpecs(plotSpec, -1, -1, plotContainer);\n",
       "           }});\n",
       "       })();\n",
       "   </script>"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "gggrid(listOf(\n",
    "    p + coordPolar(start = 3.14 / 2, direction=-1) + ggtitle(\"dir=-1, start=PI/2\"),\n",
    "    p + coordPolar(start = -3.14 / 2, direction=-1) + ggtitle(\"dir=-1, start=-PI/2\"),\n",
    "))\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "03db5bf4",
   "metadata": {},
   "source": [
    "### `xlim` and `ylim`\n",
    "The `xlim` parameter can be used to prevent overlap between the first and last values.  \n",
    "The `ylim` parameter can be used to shift data away from the centre or the outer circle.\n",
    "\n",
    "To prevent overlap between `6` and `1`, we adjust the `xlim` to `[null, 7]` while keeping the default minimum limit as it is not relevant.  \n",
    "In addition, we change `ylim` to `[null, 6.5]` to prevent the lollipop's top from overlapping with the outer circle."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "3f4cf47a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "   <div id=\"fA5dS8\"></div>\n",
       "   <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n",
       "       (function() {\n",
       "           var plotSpec={\n",
       "\"layout\":{\n",
       "\"name\":\"grid\",\n",
       "\"ncol\":2,\n",
       "\"nrow\":1,\n",
       "\"fit\":true,\n",
       "\"align\":false\n",
       "},\n",
       "\"theme\":{\n",
       "\"name\":\"grey\"\n",
       "},\n",
       "\"figures\":[{\n",
       "\"mapping\":{\n",
       "\"x\":\"x\",\n",
       "\"y\":\"y\"\n",
       "},\n",
       "\"coord\":{\n",
       "\"name\":\"polar\"\n",
       "},\n",
       "\"data\":{\n",
       "\"x\":[1.0,2.0,3.0,4.0,5.0,6.0],\n",
       "\"y\":[1.0,2.0,3.0,4.0,5.0,6.0]\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[],\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"lollipop\",\n",
       "\"data\":{\n",
       "}\n",
       "}]\n",
       "},{\n",
       "\"mapping\":{\n",
       "\"x\":\"x\",\n",
       "\"y\":\"y\"\n",
       "},\n",
       "\"coord\":{\n",
       "\"name\":\"polar\",\n",
       "\"xlim\":[null,7.0],\n",
       "\"ylim\":[null,6.5]\n",
       "},\n",
       "\"data\":{\n",
       "\"x\":[1.0,2.0,3.0,4.0,5.0,6.0],\n",
       "\"y\":[1.0,2.0,3.0,4.0,5.0,6.0]\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[],\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"lollipop\",\n",
       "\"data\":{\n",
       "}\n",
       "}]\n",
       "}],\n",
       "\"kind\":\"subplots\"\n",
       "};\n",
       "           var plotContainer = document.getElementById(\"fA5dS8\");\n",
       "           window.letsPlotCall(function() {{\n",
       "               LetsPlot.buildPlotFromProcessedSpecs(plotSpec, -1, -1, plotContainer);\n",
       "           }});\n",
       "       })();\n",
       "   </script>"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "val p = letsPlot(lollipopData) { x = \"x\"; y = \"y\" } + geomLollipop()\n",
    "\n",
    "gggrid(listOf(\n",
    "    p + coordPolar(),\n",
    "    p + coordPolar(xlim = null to 7, ylim = null to 6.5)\n",
    "))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "501d6bb5",
   "metadata": {},
   "source": [
    "# Scales  \n",
    "Interaction between scales and polar coordinate system."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "4ac54b1f",
   "metadata": {},
   "outputs": [],
   "source": [
    "val pie = letsPlot() +\n",
    "    geomRect(xmin=0, xmax=1, ymin=0, ymax=7, fill=\"red\", size=0) +\n",
    "    geomRect(xmin=1, xmax=2, ymin=0, ymax=4, fill=\"blue\", size=0) +\n",
    "    geomRect(xmin=2, xmax=3, ymin=0, ymax=3, fill=\"green\", size=0) +\n",
    "    coordPolar()\n",
    "\n",
    "val sticksData = mapOf(\n",
    "    'x' to listOf(0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5),\n",
    "    'y' to listOf(0, 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6),\n",
    "    'g' to listOf(5, 5, 4, 4, 3, 3, 2, 2, 1, 1, 0, 0)\n",
    ")\n",
    "\n",
    "val sticks = letsPlot(sticksData) + geomPath{ x='x'; y='y'; group='g'; size='g' } + coordPolar()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "82bc6009",
   "metadata": {},
   "source": [
    "## Limit\n",
    "The `limits` parameter sets the lower and upper limits individually, but expects absolute values.  \n",
    "`x=[null, 6]` limit to make the first and last elements not overlap.    \n",
    "`y=[-2, 7]` limit to make a medium sized centre hole and a small outer buffer (with a length of 1)."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "c3759240",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "   <div id=\"9npk1I\"></div>\n",
       "   <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n",
       "       (function() {\n",
       "           var plotSpec={\n",
       "\"layout\":{\n",
       "\"name\":\"grid\",\n",
       "\"ncol\":2,\n",
       "\"nrow\":1,\n",
       "\"fit\":true,\n",
       "\"align\":false\n",
       "},\n",
       "\"theme\":{\n",
       "\"name\":\"grey\"\n",
       "},\n",
       "\"figures\":[{\n",
       "\"ggtitle\":{\n",
       "\"text\":\"No limits\"\n",
       "},\n",
       "\"mapping\":{\n",
       "},\n",
       "\"coord\":{\n",
       "\"name\":\"polar\"\n",
       "},\n",
       "\"data\":{\n",
       "\"g\":[5.0,5.0,4.0,4.0,3.0,3.0,2.0,2.0,1.0,1.0,0.0,0.0],\n",
       "\"x\":[0.0,0.0,1.0,1.0,2.0,2.0,3.0,3.0,4.0,4.0,5.0,5.0],\n",
       "\"y\":[0.0,1.0,0.0,2.0,0.0,3.0,0.0,4.0,0.0,5.0,0.0,6.0]\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[],\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "\"x\":\"x\",\n",
       "\"y\":\"y\",\n",
       "\"size\":\"g\",\n",
       "\"group\":\"g\"\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"path\",\n",
       "\"data\":{\n",
       "}\n",
       "}]\n",
       "},{\n",
       "\"ggtitle\":{\n",
       "\"text\":\"lims(x=[null, 6], y=[-2, 7])\"\n",
       "},\n",
       "\"mapping\":{\n",
       "},\n",
       "\"coord\":{\n",
       "\"name\":\"polar\"\n",
       "},\n",
       "\"data\":{\n",
       "\"g\":[5.0,5.0,4.0,4.0,3.0,3.0,2.0,2.0,1.0,1.0,0.0,0.0],\n",
       "\"x\":[0.0,0.0,1.0,1.0,2.0,2.0,3.0,3.0,4.0,4.0,5.0,5.0],\n",
       "\"y\":[0.0,1.0,0.0,2.0,0.0,3.0,0.0,4.0,0.0,5.0,0.0,6.0]\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[{\n",
       "\"aesthetic\":\"x\",\n",
       "\"limits\":[null,6.0]\n",
       "},{\n",
       "\"aesthetic\":\"y\",\n",
       "\"limits\":[-2.0,7.0]\n",
       "}],\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "\"x\":\"x\",\n",
       "\"y\":\"y\",\n",
       "\"size\":\"g\",\n",
       "\"group\":\"g\"\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"path\",\n",
       "\"data\":{\n",
       "}\n",
       "}]\n",
       "}],\n",
       "\"kind\":\"subplots\"\n",
       "};\n",
       "           var plotContainer = document.getElementById(\"9npk1I\");\n",
       "           window.letsPlotCall(function() {{\n",
       "               LetsPlot.buildPlotFromProcessedSpecs(plotSpec, -1, -1, plotContainer);\n",
       "           }});\n",
       "       })();\n",
       "   </script>"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "gggrid(listOf(\n",
    "    sticks + ggtitle(\"No limits\"),\n",
    "    sticks + lims(x = null to 6, y = -2 to 7) + ggtitle(\"lims(x=[null, 6], y=[-2, 7])\"),\n",
    "))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "750b185e",
   "metadata": {},
   "source": [
    "## Discrete x-scale\n",
    "\n",
    "If the x-scale is discrete, the coordinate system will automatically adjust domain so that the first and last values don't overlap."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "f1899ecf",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "   <div id=\"TyLdYL\"></div>\n",
       "   <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n",
       "       (function() {\n",
       "           var plotSpec={\n",
       "\"layout\":{\n",
       "\"name\":\"grid\",\n",
       "\"ncol\":2,\n",
       "\"nrow\":1,\n",
       "\"fit\":true,\n",
       "\"align\":false\n",
       "},\n",
       "\"theme\":{\n",
       "\"name\":\"grey\"\n",
       "},\n",
       "\"figures\":[{\n",
       "\"ggtitle\":{\n",
       "\"text\":\"Continuous\"\n",
       "},\n",
       "\"mapping\":{\n",
       "},\n",
       "\"coord\":{\n",
       "\"name\":\"polar\"\n",
       "},\n",
       "\"data\":{\n",
       "\"g\":[5.0,5.0,4.0,4.0,3.0,3.0,2.0,2.0,1.0,1.0,0.0,0.0],\n",
       "\"x\":[0.0,0.0,1.0,1.0,2.0,2.0,3.0,3.0,4.0,4.0,5.0,5.0],\n",
       "\"y\":[0.0,1.0,0.0,2.0,0.0,3.0,0.0,4.0,0.0,5.0,0.0,6.0]\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[],\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "\"x\":\"x\",\n",
       "\"y\":\"y\",\n",
       "\"size\":\"g\",\n",
       "\"group\":\"g\"\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"path\",\n",
       "\"data\":{\n",
       "}\n",
       "}]\n",
       "},{\n",
       "\"ggtitle\":{\n",
       "\"text\":\"scaleXDiscrete()\"\n",
       "},\n",
       "\"mapping\":{\n",
       "},\n",
       "\"coord\":{\n",
       "\"name\":\"polar\"\n",
       "},\n",
       "\"data\":{\n",
       "\"g\":[5.0,5.0,4.0,4.0,3.0,3.0,2.0,2.0,1.0,1.0,0.0,0.0],\n",
       "\"x\":[0.0,0.0,1.0,1.0,2.0,2.0,3.0,3.0,4.0,4.0,5.0,5.0],\n",
       "\"y\":[0.0,1.0,0.0,2.0,0.0,3.0,0.0,4.0,0.0,5.0,0.0,6.0]\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[{\n",
       "\"aesthetic\":\"x\",\n",
       "\"discrete\":true\n",
       "}],\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "\"x\":\"x\",\n",
       "\"y\":\"y\",\n",
       "\"size\":\"g\",\n",
       "\"group\":\"g\"\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"path\",\n",
       "\"data\":{\n",
       "}\n",
       "}]\n",
       "}],\n",
       "\"kind\":\"subplots\"\n",
       "};\n",
       "           var plotContainer = document.getElementById(\"TyLdYL\");\n",
       "           window.letsPlotCall(function() {{\n",
       "               LetsPlot.buildPlotFromProcessedSpecs(plotSpec, -1, -1, plotContainer);\n",
       "           }});\n",
       "       })();\n",
       "   </script>"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "gggrid(listOf(\n",
    "    sticks + ggtitle(\"Continuous\"), \n",
    "    sticks + scaleXDiscrete() + ggtitle(\"scaleXDiscrete()\")\n",
    "))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "38f9d4dc",
   "metadata": {},
   "source": [
    "## clip-path\n",
    "\n",
    "Segments should not get rendered outside the panel boundaries."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "cbc4db9e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "   <div id=\"EUCko4\"></div>\n",
       "   <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n",
       "       (function() {\n",
       "           var plotSpec={\n",
       "\"layout\":{\n",
       "\"name\":\"grid\",\n",
       "\"ncol\":2,\n",
       "\"nrow\":1,\n",
       "\"fit\":true,\n",
       "\"align\":false\n",
       "},\n",
       "\"theme\":{\n",
       "\"name\":\"grey\"\n",
       "},\n",
       "\"figures\":[{\n",
       "\"mapping\":{\n",
       "},\n",
       "\"coord\":{\n",
       "\"name\":\"polar\"\n",
       "},\n",
       "\"data\":{\n",
       "\"g\":[5.0,5.0,4.0,4.0,3.0,3.0,2.0,2.0,1.0,1.0,0.0,0.0],\n",
       "\"x\":[0.0,0.0,1.0,1.0,2.0,2.0,3.0,3.0,4.0,4.0,5.0,5.0],\n",
       "\"y\":[0.0,1.0,0.0,2.0,0.0,3.0,0.0,4.0,0.0,5.0,0.0,6.0]\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[],\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "\"x\":\"x\",\n",
       "\"y\":\"y\",\n",
       "\"size\":\"g\",\n",
       "\"group\":\"g\"\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"path\",\n",
       "\"data\":{\n",
       "}\n",
       "}]\n",
       "},{\n",
       "\"mapping\":{\n",
       "},\n",
       "\"coord\":{\n",
       "\"name\":\"polar\",\n",
       "\"ylim\":[0.0,1.5]\n",
       "},\n",
       "\"data\":{\n",
       "\"g\":[5.0,5.0,4.0,4.0,3.0,3.0,2.0,2.0,1.0,1.0,0.0,0.0],\n",
       "\"x\":[0.0,0.0,1.0,1.0,2.0,2.0,3.0,3.0,4.0,4.0,5.0,5.0],\n",
       "\"y\":[0.0,1.0,0.0,2.0,0.0,3.0,0.0,4.0,0.0,5.0,0.0,6.0]\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[],\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "\"x\":\"x\",\n",
       "\"y\":\"y\",\n",
       "\"size\":\"g\",\n",
       "\"group\":\"g\"\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"path\",\n",
       "\"data\":{\n",
       "}\n",
       "}]\n",
       "}],\n",
       "\"kind\":\"subplots\"\n",
       "};\n",
       "           var plotContainer = document.getElementById(\"EUCko4\");\n",
       "           window.letsPlotCall(function() {{\n",
       "               LetsPlot.buildPlotFromProcessedSpecs(plotSpec, -1, -1, plotContainer);\n",
       "           }});\n",
       "       })();\n",
       "   </script>"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "gggrid(listOf(\n",
    "    sticks,\n",
    "    sticks + coordPolar(ylim = 0 to 1.5)\n",
    "))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6c436bf7",
   "metadata": {},
   "source": [
    "## Expand\n",
    "By default `coordPolar()` resets the expansion to zero, but it can still be set explicitly.  \n",
    "Horizontal non-zero expand will produce a gap between first and last sectors, so the plot will never become a circle.  \n",
    "Vertical non-zero expand creates a central hole (expand for the bottom of the domain) and a buffer between the plot and the axis (expand for the top of the domain).  \n",
    "\n",
    "`expand` is symmetric, so it can't be used to adjust only the bottom or only the top."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "a6c0d738",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "   <div id=\"vjDClK\"></div>\n",
       "   <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n",
       "       (function() {\n",
       "           var plotSpec={\n",
       "\"layout\":{\n",
       "\"name\":\"grid\",\n",
       "\"ncol\":2,\n",
       "\"nrow\":1,\n",
       "\"fit\":true,\n",
       "\"align\":false\n",
       "},\n",
       "\"theme\":{\n",
       "\"name\":\"grey\"\n",
       "},\n",
       "\"figures\":[{\n",
       "\"ggtitle\":{\n",
       "\"text\":\"No expand\"\n",
       "},\n",
       "\"mapping\":{\n",
       "},\n",
       "\"coord\":{\n",
       "\"name\":\"polar\"\n",
       "},\n",
       "\"data\":{\n",
       "\"g\":[5.0,5.0,4.0,4.0,3.0,3.0,2.0,2.0,1.0,1.0,0.0,0.0],\n",
       "\"x\":[0.0,0.0,1.0,1.0,2.0,2.0,3.0,3.0,4.0,4.0,5.0,5.0],\n",
       "\"y\":[0.0,1.0,0.0,2.0,0.0,3.0,0.0,4.0,0.0,5.0,0.0,6.0]\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[],\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "\"x\":\"x\",\n",
       "\"y\":\"y\",\n",
       "\"size\":\"g\",\n",
       "\"group\":\"g\"\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"path\",\n",
       "\"data\":{\n",
       "}\n",
       "}]\n",
       "},{\n",
       "\"ggtitle\":{\n",
       "\"text\":\"scale_XY_continuous(expand=...)\"\n",
       "},\n",
       "\"mapping\":{\n",
       "},\n",
       "\"coord\":{\n",
       "\"name\":\"polar\"\n",
       "},\n",
       "\"data\":{\n",
       "\"g\":[5.0,5.0,4.0,4.0,3.0,3.0,2.0,2.0,1.0,1.0,0.0,0.0],\n",
       "\"x\":[0.0,0.0,1.0,1.0,2.0,2.0,3.0,3.0,4.0,4.0,5.0,5.0],\n",
       "\"y\":[0.0,1.0,0.0,2.0,0.0,3.0,0.0,4.0,0.0,5.0,0.0,6.0]\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[{\n",
       "\"aesthetic\":\"x\",\n",
       "\"expand\":[0,2.5]\n",
       "},{\n",
       "\"aesthetic\":\"y\",\n",
       "\"expand\":[0,2]\n",
       "}],\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "\"x\":\"x\",\n",
       "\"y\":\"y\",\n",
       "\"size\":\"g\",\n",
       "\"group\":\"g\"\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"path\",\n",
       "\"data\":{\n",
       "}\n",
       "}]\n",
       "}],\n",
       "\"kind\":\"subplots\"\n",
       "};\n",
       "           var plotContainer = document.getElementById(\"vjDClK\");\n",
       "           window.letsPlotCall(function() {{\n",
       "               LetsPlot.buildPlotFromProcessedSpecs(plotSpec, -1, -1, plotContainer);\n",
       "           }});\n",
       "       })();\n",
       "   </script>"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "gggrid(listOf(\n",
    "    sticks + ggtitle(\"No expand\"),\n",
    "    sticks + scaleXContinuous(expand = listOf(0, 2.5)) + \n",
    "        scaleYContinuous(expand = listOf(0, 2)) + \n",
    "        ggtitle(\"scale_XY_continuous(expand=...)\")\n",
    "))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3dc9bef7",
   "metadata": {},
   "source": [
    "## `scaleYLog10()`  \n",
    "Log-scale works fine."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "8996ddb9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "   <div id=\"23wuhc\"></div>\n",
       "   <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n",
       "       (function() {\n",
       "           var plotSpec={\n",
       "\"layout\":{\n",
       "\"name\":\"grid\",\n",
       "\"ncol\":2,\n",
       "\"nrow\":2,\n",
       "\"fit\":true,\n",
       "\"align\":false\n",
       "},\n",
       "\"theme\":{\n",
       "\"name\":\"grey\"\n",
       "},\n",
       "\"figures\":[{\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "\"x\":\"x\",\n",
       "\"y\":\"y\"\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"flat\":true,\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"path\",\n",
       "\"data\":{\n",
       "}\n",
       "}],\n",
       "\"mapping\":{\n",
       "},\n",
       "\"data\":{\n",
       "\"x\":[1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0],\n",
       "\"y\":[1.0,10.0,100.0,1000.0,10000.0,100000.0,1000000.0,1.0E7]\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[]\n",
       "},{\n",
       "\"mapping\":{\n",
       "},\n",
       "\"coord\":{\n",
       "\"name\":\"polar\"\n",
       "},\n",
       "\"data\":{\n",
       "\"x\":[1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0],\n",
       "\"y\":[1.0,10.0,100.0,1000.0,10000.0,100000.0,1000000.0,1.0E7]\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[],\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "\"x\":\"x\",\n",
       "\"y\":\"y\"\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"flat\":true,\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"path\",\n",
       "\"data\":{\n",
       "}\n",
       "}]\n",
       "},{\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "\"x\":\"x\",\n",
       "\"y\":\"y\"\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"flat\":true,\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"path\",\n",
       "\"data\":{\n",
       "}\n",
       "}],\n",
       "\"mapping\":{\n",
       "},\n",
       "\"data\":{\n",
       "\"x\":[1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0],\n",
       "\"y\":[1.0,10.0,100.0,1000.0,10000.0,100000.0,1000000.0,1.0E7]\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[{\n",
       "\"aesthetic\":\"y\",\n",
       "\"trans\":\"log10\"\n",
       "}]\n",
       "},{\n",
       "\"mapping\":{\n",
       "},\n",
       "\"coord\":{\n",
       "\"name\":\"polar\"\n",
       "},\n",
       "\"data\":{\n",
       "\"x\":[1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0],\n",
       "\"y\":[1.0,10.0,100.0,1000.0,10000.0,100000.0,1000000.0,1.0E7]\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[{\n",
       "\"aesthetic\":\"y\",\n",
       "\"format\":\".1~e\",\n",
       "\"trans\":\"log10\"\n",
       "}],\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "\"x\":\"x\",\n",
       "\"y\":\"y\"\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"flat\":true,\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"path\",\n",
       "\"data\":{\n",
       "}\n",
       "}]\n",
       "}],\n",
       "\"kind\":\"subplots\"\n",
       "};\n",
       "           var plotContainer = document.getElementById(\"23wuhc\");\n",
       "           window.letsPlotCall(function() {{\n",
       "               LetsPlot.buildPlotFromProcessedSpecs(plotSpec, -1, -1, plotContainer);\n",
       "           }});\n",
       "       })();\n",
       "   </script>"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "val d = mapOf(\n",
    "    'x' to listOf(1, 2, 3, 4, 5, 6, 7, 8),\n",
    "    'y' to listOf(1, 10, 100, 1_000, 10_000, 100_000, 1_000_000, 10_000_000),\n",
    ")\n",
    "val p = letsPlot(d) + geomPath(flat = true) { x='x'; y='y'}\n",
    "p\n",
    "\n",
    "gggrid(listOf(\n",
    "    p,\n",
    "    p + coordPolar(),\n",
    "    p + scaleYLog10(),\n",
    "    p + scaleYLog10(format=\".1~e\") + coordPolar(),\n",
    "), ncol = 2)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "57de96bf",
   "metadata": {},
   "source": [
    "# Theme"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "28b82be5",
   "metadata": {},
   "outputs": [],
   "source": [
    "val p = letsPlot(labelsData) { x = \"x\"; y = \"y\"; color = \"y\" } + \n",
    "    scaleColorBrewer(palette = \"GnBu\") +\n",
    "    geomPath(size = 3)\n",
    "\n",
    "val polar_p = p + coordPolar()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "abca1ba2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "   <div id=\"hFVlnv\"></div>\n",
       "   <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n",
       "       (function() {\n",
       "           var plotSpec={\n",
       "\"layout\":{\n",
       "\"name\":\"grid\",\n",
       "\"ncol\":3,\n",
       "\"nrow\":3,\n",
       "\"fit\":true,\n",
       "\"align\":false\n",
       "},\n",
       "\"theme\":{\n",
       "\"name\":\"grey\"\n",
       "},\n",
       "\"figures\":[{\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"size\":3.0,\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"path\",\n",
       "\"data\":{\n",
       "}\n",
       "}],\n",
       "\"mapping\":{\n",
       "\"x\":\"x\",\n",
       "\"y\":\"y\",\n",
       "\"color\":\"y\"\n",
       "},\n",
       "\"data\":{\n",
       "\"x\":[0.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0],\n",
       "\"y\":[0.0,45.0,90.0,135.0,180.0,225.0,270.0,315.0,360.0]\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[{\n",
       "\"aesthetic\":\"color\",\n",
       "\"scale_mapper_kind\":\"color_brewer\",\n",
       "\"palette\":\"GnBu\"\n",
       "}]\n",
       "},{\n",
       "\"ggtitle\":{\n",
       "\"text\":\"minimal2\"\n",
       "},\n",
       "\"mapping\":{\n",
       "\"x\":\"x\",\n",
       "\"y\":\"y\",\n",
       "\"color\":\"y\"\n",
       "},\n",
       "\"coord\":{\n",
       "\"name\":\"polar\"\n",
       "},\n",
       "\"data\":{\n",
       "\"x\":[0.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0],\n",
       "\"y\":[0.0,45.0,90.0,135.0,180.0,225.0,270.0,315.0,360.0]\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[{\n",
       "\"aesthetic\":\"color\",\n",
       "\"scale_mapper_kind\":\"color_brewer\",\n",
       "\"palette\":\"GnBu\"\n",
       "}],\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"size\":3.0,\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"path\",\n",
       "\"data\":{\n",
       "}\n",
       "}],\n",
       "\"theme\":{\n",
       "\"name\":\"minimal2\"\n",
       "}\n",
       "},{\n",
       "\"ggtitle\":{\n",
       "\"text\":\"bw\"\n",
       "},\n",
       "\"mapping\":{\n",
       "\"x\":\"x\",\n",
       "\"y\":\"y\",\n",
       "\"color\":\"y\"\n",
       "},\n",
       "\"coord\":{\n",
       "\"name\":\"polar\"\n",
       "},\n",
       "\"data\":{\n",
       "\"x\":[0.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0],\n",
       "\"y\":[0.0,45.0,90.0,135.0,180.0,225.0,270.0,315.0,360.0]\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[{\n",
       "\"aesthetic\":\"color\",\n",
       "\"scale_mapper_kind\":\"color_brewer\",\n",
       "\"palette\":\"GnBu\"\n",
       "}],\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"size\":3.0,\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"path\",\n",
       "\"data\":{\n",
       "}\n",
       "}],\n",
       "\"theme\":{\n",
       "\"name\":\"bw\"\n",
       "}\n",
       "},{\n",
       "\"ggtitle\":{\n",
       "\"text\":\"classic\"\n",
       "},\n",
       "\"mapping\":{\n",
       "\"x\":\"x\",\n",
       "\"y\":\"y\",\n",
       "\"color\":\"y\"\n",
       "},\n",
       "\"coord\":{\n",
       "\"name\":\"polar\"\n",
       "},\n",
       "\"data\":{\n",
       "\"x\":[0.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0],\n",
       "\"y\":[0.0,45.0,90.0,135.0,180.0,225.0,270.0,315.0,360.0]\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[{\n",
       "\"aesthetic\":\"color\",\n",
       "\"scale_mapper_kind\":\"color_brewer\",\n",
       "\"palette\":\"GnBu\"\n",
       "}],\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"size\":3.0,\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"path\",\n",
       "\"data\":{\n",
       "}\n",
       "}],\n",
       "\"theme\":{\n",
       "\"name\":\"classic\"\n",
       "}\n",
       "},{\n",
       "\"ggtitle\":{\n",
       "\"text\":\"grey\"\n",
       "},\n",
       "\"mapping\":{\n",
       "\"x\":\"x\",\n",
       "\"y\":\"y\",\n",
       "\"color\":\"y\"\n",
       "},\n",
       "\"coord\":{\n",
       "\"name\":\"polar\"\n",
       "},\n",
       "\"data\":{\n",
       "\"x\":[0.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0],\n",
       "\"y\":[0.0,45.0,90.0,135.0,180.0,225.0,270.0,315.0,360.0]\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[{\n",
       "\"aesthetic\":\"color\",\n",
       "\"scale_mapper_kind\":\"color_brewer\",\n",
       "\"palette\":\"GnBu\"\n",
       "}],\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"size\":3.0,\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"path\",\n",
       "\"data\":{\n",
       "}\n",
       "}]\n",
       "},{\n",
       "\"ggtitle\":{\n",
       "\"text\":\"light\"\n",
       "},\n",
       "\"mapping\":{\n",
       "\"x\":\"x\",\n",
       "\"y\":\"y\",\n",
       "\"color\":\"y\"\n",
       "},\n",
       "\"coord\":{\n",
       "\"name\":\"polar\"\n",
       "},\n",
       "\"data\":{\n",
       "\"x\":[0.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0],\n",
       "\"y\":[0.0,45.0,90.0,135.0,180.0,225.0,270.0,315.0,360.0]\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[{\n",
       "\"aesthetic\":\"color\",\n",
       "\"scale_mapper_kind\":\"color_brewer\",\n",
       "\"palette\":\"GnBu\"\n",
       "}],\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"size\":3.0,\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"path\",\n",
       "\"data\":{\n",
       "}\n",
       "}],\n",
       "\"theme\":{\n",
       "\"name\":\"light\"\n",
       "}\n",
       "},{\n",
       "\"ggtitle\":{\n",
       "\"text\":\"minimal\"\n",
       "},\n",
       "\"mapping\":{\n",
       "\"x\":\"x\",\n",
       "\"y\":\"y\",\n",
       "\"color\":\"y\"\n",
       "},\n",
       "\"coord\":{\n",
       "\"name\":\"polar\"\n",
       "},\n",
       "\"data\":{\n",
       "\"x\":[0.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0],\n",
       "\"y\":[0.0,45.0,90.0,135.0,180.0,225.0,270.0,315.0,360.0]\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[{\n",
       "\"aesthetic\":\"color\",\n",
       "\"scale_mapper_kind\":\"color_brewer\",\n",
       "\"palette\":\"GnBu\"\n",
       "}],\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"size\":3.0,\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"path\",\n",
       "\"data\":{\n",
       "}\n",
       "}],\n",
       "\"theme\":{\n",
       "\"name\":\"minimal\"\n",
       "}\n",
       "},{\n",
       "\"ggtitle\":{\n",
       "\"text\":\"none\"\n",
       "},\n",
       "\"mapping\":{\n",
       "\"x\":\"x\",\n",
       "\"y\":\"y\",\n",
       "\"color\":\"y\"\n",
       "},\n",
       "\"coord\":{\n",
       "\"name\":\"polar\"\n",
       "},\n",
       "\"data\":{\n",
       "\"x\":[0.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0],\n",
       "\"y\":[0.0,45.0,90.0,135.0,180.0,225.0,270.0,315.0,360.0]\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[{\n",
       "\"aesthetic\":\"color\",\n",
       "\"scale_mapper_kind\":\"color_brewer\",\n",
       "\"palette\":\"GnBu\"\n",
       "}],\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"size\":3.0,\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"path\",\n",
       "\"data\":{\n",
       "}\n",
       "}],\n",
       "\"theme\":{\n",
       "\"name\":\"none\"\n",
       "}\n",
       "},{\n",
       "\"ggtitle\":{\n",
       "\"text\":\"void\"\n",
       "},\n",
       "\"mapping\":{\n",
       "\"x\":\"x\",\n",
       "\"y\":\"y\",\n",
       "\"color\":\"y\"\n",
       "},\n",
       "\"coord\":{\n",
       "\"name\":\"polar\"\n",
       "},\n",
       "\"data\":{\n",
       "\"x\":[0.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0],\n",
       "\"y\":[0.0,45.0,90.0,135.0,180.0,225.0,270.0,315.0,360.0]\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[{\n",
       "\"aesthetic\":\"color\",\n",
       "\"scale_mapper_kind\":\"color_brewer\",\n",
       "\"palette\":\"GnBu\"\n",
       "}],\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"size\":3.0,\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"path\",\n",
       "\"data\":{\n",
       "}\n",
       "}],\n",
       "\"theme\":{\n",
       "\"name\":\"classic\",\n",
       "\"axis\":{\n",
       "\"blank\":true\n",
       "},\n",
       "\"line\":{\n",
       "\"blank\":true\n",
       "}\n",
       "}\n",
       "}],\n",
       "\"kind\":\"subplots\"\n",
       "};\n",
       "           var plotContainer = document.getElementById(\"hFVlnv\");\n",
       "           window.letsPlotCall(function() {{\n",
       "               LetsPlot.buildPlotFromProcessedSpecs(plotSpec, -1, -1, plotContainer);\n",
       "           }});\n",
       "       })();\n",
       "   </script>"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "gggrid(listOf(\n",
    "    p,\n",
    "    polar_p + themeMinimal2() + ggtitle(\"minimal2\"),\n",
    "    polar_p + themeBW() + ggtitle(\"bw\"),\n",
    "    polar_p + themeClassic() + ggtitle(\"classic\"),\n",
    "    polar_p + themeGrey() + ggtitle(\"grey\"),\n",
    "    polar_p + themeLight() + ggtitle(\"light\"),\n",
    "    polar_p + themeMinimal() + ggtitle(\"minimal\"),\n",
    "    polar_p + themeNone() + ggtitle(\"none\"),\n",
    "    polar_p + themeVoid() + ggtitle(\"void\"),\n",
    "), ncol = 3)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2638d700",
   "metadata": {},
   "source": [
    "## Axis configuration"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "6621bf5e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "   <div id=\"k2zWrn\"></div>\n",
       "   <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n",
       "       (function() {\n",
       "           var plotSpec={\n",
       "\"layout\":{\n",
       "\"name\":\"grid\",\n",
       "\"ncol\":2,\n",
       "\"nrow\":1,\n",
       "\"fit\":true,\n",
       "\"align\":false\n",
       "},\n",
       "\"theme\":{\n",
       "\"name\":\"grey\"\n",
       "},\n",
       "\"figures\":[{\n",
       "\"mapping\":{\n",
       "\"x\":\"x\",\n",
       "\"y\":\"y\",\n",
       "\"color\":\"y\"\n",
       "},\n",
       "\"data\":{\n",
       "\"x\":[0.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0],\n",
       "\"y\":[0.0,45.0,90.0,135.0,180.0,225.0,270.0,315.0,360.0]\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[{\n",
       "\"aesthetic\":\"color\",\n",
       "\"scale_mapper_kind\":\"color_brewer\",\n",
       "\"palette\":\"GnBu\"\n",
       "}],\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"size\":3.0,\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"path\",\n",
       "\"data\":{\n",
       "}\n",
       "}],\n",
       "\"theme\":{\n",
       "\"name\":\"grey\",\n",
       "\"axis_text_y\":{\n",
       "\"color\":\"red\",\n",
       "\"blank\":false\n",
       "},\n",
       "\"axis_ticks_length_y\":5.0,\n",
       "\"axis_text_x\":{\n",
       "\"color\":\"blue\",\n",
       "\"blank\":false\n",
       "},\n",
       "\"axis_ticks_length_x\":10.0,\n",
       "\"axis_ticks_x\":{\n",
       "\"color\":\"blue\",\n",
       "\"size\":3.0,\n",
       "\"blank\":false\n",
       "},\n",
       "\"axis_ticks_y\":{\n",
       "\"color\":\"red\",\n",
       "\"size\":5.0,\n",
       "\"blank\":false\n",
       "},\n",
       "\"axis_line_x\":{\n",
       "\"color\":\"blue\",\n",
       "\"size\":2.0,\n",
       "\"blank\":false\n",
       "},\n",
       "\"axis_line_y\":{\n",
       "\"color\":\"red\",\n",
       "\"size\":2.0,\n",
       "\"blank\":false\n",
       "}\n",
       "}\n",
       "},{\n",
       "\"mapping\":{\n",
       "\"x\":\"x\",\n",
       "\"y\":\"y\",\n",
       "\"color\":\"y\"\n",
       "},\n",
       "\"coord\":{\n",
       "\"name\":\"polar\"\n",
       "},\n",
       "\"data\":{\n",
       "\"x\":[0.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0],\n",
       "\"y\":[0.0,45.0,90.0,135.0,180.0,225.0,270.0,315.0,360.0]\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[{\n",
       "\"aesthetic\":\"color\",\n",
       "\"scale_mapper_kind\":\"color_brewer\",\n",
       "\"palette\":\"GnBu\"\n",
       "}],\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"size\":3.0,\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"path\",\n",
       "\"data\":{\n",
       "}\n",
       "}],\n",
       "\"theme\":{\n",
       "\"name\":\"grey\",\n",
       "\"axis_text_y\":{\n",
       "\"color\":\"red\",\n",
       "\"blank\":false\n",
       "},\n",
       "\"axis_ticks_length_y\":5.0,\n",
       "\"axis_text_x\":{\n",
       "\"color\":\"blue\",\n",
       "\"blank\":false\n",
       "},\n",
       "\"axis_ticks_length_x\":10.0,\n",
       "\"axis_ticks_x\":{\n",
       "\"color\":\"blue\",\n",
       "\"size\":3.0,\n",
       "\"blank\":false\n",
       "},\n",
       "\"axis_ticks_y\":{\n",
       "\"color\":\"red\",\n",
       "\"size\":5.0,\n",
       "\"blank\":false\n",
       "},\n",
       "\"axis_line_x\":{\n",
       "\"color\":\"blue\",\n",
       "\"size\":2.0,\n",
       "\"blank\":false\n",
       "},\n",
       "\"axis_line_y\":{\n",
       "\"color\":\"red\",\n",
       "\"size\":2.0,\n",
       "\"blank\":false\n",
       "}\n",
       "}\n",
       "}],\n",
       "\"kind\":\"subplots\"\n",
       "};\n",
       "           var plotContainer = document.getElementById(\"k2zWrn\");\n",
       "           window.letsPlotCall(function() {{\n",
       "               LetsPlot.buildPlotFromProcessedSpecs(plotSpec, -1, -1, plotContainer);\n",
       "           }});\n",
       "       })();\n",
       "   </script>"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "val p_tmp = p + theme(\n",
    "    axisLineY = elementLine(color=\"red\", size=2),\n",
    "    axisLineX = elementLine(color=\"blue\", size=2),\n",
    "    axisTicksLengthY = 5,\n",
    "    axisTicksLengthX = 10,\n",
    "    axisTicksY = elementLine(size=5, color=\"red\"), \n",
    "    axisTicksX = elementLine(size=3, color=\"blue\"),\n",
    "    axisTextX = elementText(color=\"blue\"),\n",
    "    axisTextY = elementText(color=\"red\"),\n",
    ")\n",
    "\n",
    "gggrid(listOf(\n",
    "    p_tmp,\n",
    "    p_tmp + coordPolar()\n",
    "))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e92a5688",
   "metadata": {},
   "source": [
    "## panelInset\n",
    "The `panelInset` parameter can be used to create space between the axis and the panel content:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "33536bf1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "   <div id=\"kdolyx\"></div>\n",
       "   <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n",
       "       (function() {\n",
       "           var plotSpec={\n",
       "\"layout\":{\n",
       "\"name\":\"grid\",\n",
       "\"ncol\":2,\n",
       "\"nrow\":1,\n",
       "\"fit\":true,\n",
       "\"align\":false\n",
       "},\n",
       "\"theme\":{\n",
       "\"name\":\"grey\"\n",
       "},\n",
       "\"figures\":[{\n",
       "\"mapping\":{\n",
       "\"x\":\"x\",\n",
       "\"y\":\"y\",\n",
       "\"color\":\"y\"\n",
       "},\n",
       "\"data\":{\n",
       "\"x\":[0.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0],\n",
       "\"y\":[0.0,45.0,90.0,135.0,180.0,225.0,270.0,315.0,360.0]\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[{\n",
       "\"aesthetic\":\"color\",\n",
       "\"scale_mapper_kind\":\"color_brewer\",\n",
       "\"palette\":\"GnBu\"\n",
       "}],\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"size\":3.0,\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"path\",\n",
       "\"data\":{\n",
       "}\n",
       "}],\n",
       "\"theme\":{\n",
       "\"name\":\"grey\",\n",
       "\"axis_text_y\":{\n",
       "\"color\":\"red\",\n",
       "\"blank\":false\n",
       "},\n",
       "\"axis_ticks_length_y\":5.0,\n",
       "\"axis_text_x\":{\n",
       "\"color\":\"blue\",\n",
       "\"blank\":false\n",
       "},\n",
       "\"axis_ticks_length_x\":10.0,\n",
       "\"axis_ticks_x\":{\n",
       "\"color\":\"blue\",\n",
       "\"size\":3.0,\n",
       "\"blank\":false\n",
       "},\n",
       "\"axis_ticks_y\":{\n",
       "\"color\":\"red\",\n",
       "\"size\":5.0,\n",
       "\"blank\":false\n",
       "},\n",
       "\"axis_line_x\":{\n",
       "\"color\":\"blue\",\n",
       "\"size\":2.0,\n",
       "\"blank\":false\n",
       "},\n",
       "\"axis_line_y\":{\n",
       "\"color\":\"red\",\n",
       "\"size\":2.0,\n",
       "\"blank\":false\n",
       "},\n",
       "\"plot_background\":{\n",
       "\"fill\":\"pink\",\n",
       "\"blank\":false\n",
       "},\n",
       "\"panel_background\":{\n",
       "\"fill\":\"grey\",\n",
       "\"blank\":false\n",
       "},\n",
       "\"panel_inset\":10.0,\n",
       "\"panel_border\":{\n",
       "\"color\":\"green\",\n",
       "\"size\":1.0,\n",
       "\"blank\":false\n",
       "}\n",
       "}\n",
       "},{\n",
       "\"mapping\":{\n",
       "\"x\":\"x\",\n",
       "\"y\":\"y\",\n",
       "\"color\":\"y\"\n",
       "},\n",
       "\"coord\":{\n",
       "\"name\":\"polar\"\n",
       "},\n",
       "\"data\":{\n",
       "\"x\":[0.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0],\n",
       "\"y\":[0.0,45.0,90.0,135.0,180.0,225.0,270.0,315.0,360.0]\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[{\n",
       "\"aesthetic\":\"color\",\n",
       "\"scale_mapper_kind\":\"color_brewer\",\n",
       "\"palette\":\"GnBu\"\n",
       "}],\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"size\":3.0,\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"path\",\n",
       "\"data\":{\n",
       "}\n",
       "}],\n",
       "\"theme\":{\n",
       "\"name\":\"grey\",\n",
       "\"axis_text_y\":{\n",
       "\"color\":\"red\",\n",
       "\"blank\":false\n",
       "},\n",
       "\"axis_ticks_length_y\":5.0,\n",
       "\"axis_text_x\":{\n",
       "\"color\":\"blue\",\n",
       "\"blank\":false\n",
       "},\n",
       "\"axis_ticks_length_x\":10.0,\n",
       "\"axis_ticks_x\":{\n",
       "\"color\":\"blue\",\n",
       "\"size\":3.0,\n",
       "\"blank\":false\n",
       "},\n",
       "\"axis_ticks_y\":{\n",
       "\"color\":\"red\",\n",
       "\"size\":5.0,\n",
       "\"blank\":false\n",
       "},\n",
       "\"axis_line_x\":{\n",
       "\"color\":\"blue\",\n",
       "\"size\":2.0,\n",
       "\"blank\":false\n",
       "},\n",
       "\"axis_line_y\":{\n",
       "\"color\":\"red\",\n",
       "\"size\":2.0,\n",
       "\"blank\":false\n",
       "},\n",
       "\"plot_background\":{\n",
       "\"fill\":\"pink\",\n",
       "\"blank\":false\n",
       "},\n",
       "\"panel_background\":{\n",
       "\"fill\":\"grey\",\n",
       "\"blank\":false\n",
       "},\n",
       "\"panel_inset\":10.0,\n",
       "\"panel_border\":{\n",
       "\"color\":\"green\",\n",
       "\"size\":1.0,\n",
       "\"blank\":false\n",
       "}\n",
       "}\n",
       "}],\n",
       "\"kind\":\"subplots\"\n",
       "};\n",
       "           var plotContainer = document.getElementById(\"kdolyx\");\n",
       "           window.letsPlotCall(function() {{\n",
       "               LetsPlot.buildPlotFromProcessedSpecs(plotSpec, -1, -1, plotContainer);\n",
       "           }});\n",
       "       })();\n",
       "   </script>"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "val p_themed = p_tmp + theme(\n",
    "    plotBackground = elementRect(fill=\"pink\"),\n",
    "    panelBackground = elementRect(fill=\"grey\"),\n",
    "    panelBorder = elementRect(color=\"green\", size=1),\n",
    "    panelInset = 10\n",
    ")\n",
    "\n",
    "gggrid(listOf(\n",
    "    p_themed,\n",
    "    p_themed + coordPolar()\n",
    "))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Kotlin",
   "language": "kotlin",
   "name": "kotlin"
  },
  "language_info": {
   "codemirror_mode": "text/x-kotlin",
   "file_extension": ".kt",
   "mimetype": "text/x-kotlin",
   "name": "kotlin",
   "nbconvert_exporter": "",
   "pygments_lexer": "kotlin",
   "version": "1.8.0-dev-3517"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
